Extract Local Maxima
Python, 54 bytes
f=lambda l,*p:l and l[:p<=l[:1]>=l[1:2]]+f(l[1:],l[0])
Try it online!
I/O is with tuples rather than lists.
Python, 57 bytes
f=lambda l,p=0:l and l[:[p]<=l[:1]>=l[1:2]]+f(l[1:],l[0])
Try it online!
Alt 57:
f=lambda l,p=0:l and l[l<[max(p,*l[:2])]:1]+f(l[1:],l[0])
Mathematica 22 Bytes
Pick[#,MaxDetect@#,1]&
Haskell, 50 49 42 bytes
f l=[j|i:j:k:_<-scanr(:)[0]$0:l,k<=j,i<=j]
Try it online!
scanr(:)[0]
makes a list of the tails of (0:l)
, each with a final 0
, e.g. for l = [4,3,3,4]
: [[0,4,3,3,4,0],[4,3,3,4,0],[3,3,4,0],[3,4,0],[4,0],[0]]
which is pattern matched agains i:j:k:_
to extract all lists with at least 3 elements which are named i
, j
, and k
. Keep j
if its >= i
and j
.
Edit: Ørjan Johansen saved 7 bytes. Thanks!