in reply to Re: finding local minima/maxima for a discrete array
in thread finding local minima/maxima for a discrete array
You can't do the $d1 = $d when $d is 0 or you treat the transition between 2 and 3 as significant in 1 2 2 3. I think your $d * $d1 <= 0 && $d != 0 is the same (only slightly slower, not faster as you guess) as $d && $d != $d1 with $d set by <=> instead of -. With the final checks after the for loop being > and < , it's treated as neither a minimum or maximum when the whole array is equal; with >= and <= instead it's treated as both. You could argue for either way.