From 7b546dd5e7dc03b96c63316e9c42334ac43be345 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 6 Sep 2022 10:44:24 +0200 Subject: [PATCH] Modified the function to pass all tests --- hands_on/local_maxima/local_maxima.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hands_on/local_maxima/local_maxima.py b/hands_on/local_maxima/local_maxima.py index 1575179..9a64704 100644 --- a/hands_on/local_maxima/local_maxima.py +++ b/hands_on/local_maxima/local_maxima.py @@ -19,4 +19,20 @@ def local_maxima(x): Output: idx -- list of indices of the local maxima in x """ - return [] + max_ls = [] + for i in range(len(x)): + if i ==0: + if x[i] > x[i+1]: + max_ls.append(i) + elif i == len(x)-1: + if x[i] > x[i-1]: + max_ls.append(i) + else: + if x[i] >= x[i+1] and x[i] >= x[i-1]: + max_ls.append(i) + return max_ls + + + + +