Ruby, 41 3732 characters
->a{m,=a;a.select{|n|m<=n&&m=n}}
Thanks to:
- Value Ink for reminding that in Ruby all numbers are truthy, so
&&
number assignment does not change the preceding boolean expression.
Ruby, 41 37 characters
->a{m=a[0];a.map{|n|m>n ?p: m=n}-[p]}
(My old attempt.)
Sample run:
2.1.5 :001 > [
2.1.5 :002 > [1, 2, 5, 4, 3, 7],
2.1.5 :003 > [10, -1, 12],
2.1.5 :004 > [-7, -8, -5, 0, -1, 1],
2.1.5 :005 > [9, 8, 7, 6, 5],
2.1.5 :006 > [10, 13, 17, 21],
2.1.5 :007 > [10, 10, 10, 9, 10],
2.1.5 :008 > ].each{ |test| p ->a{m=a[0];a.map{|n|m>n ?p: m=n}-[p]}[test] }
[1, 2, 5, 7]
[10, 12]
[-7, -5, 0, 1]
[9]
[10, 13, 17, 21]
[10, 10, 10, 10]