The Spike Locator
HardAcc. 72.1%
+45 XP 25
Peaks in the Data
A "spike" is a value that is strictly greater than the element before it and the element after it.
The Assignment
Your function receives an array of numbers.
- Loop from index 1 to array.length - 2.
- If the current value is greater than its left neighbor and greater than its right neighbor, print the value.
- Every spike should be on a new line.
01EXAMPLE 1
Input
[1, 4, 2, 5, 3]Output
4
5Explanation: 4 > (1,2) and 5 > (2,3).
Constraints
- Ignore the first and last elements (they only have one neighbor).
ArraysLoopsLogic
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
data[1,4,2,5,3]
Expected Output
4 5
Click RUN to test your solution