Given an array of unsorted positive ints, write a function that finds runs of 3 consecutive numbers (ascending or descending) and returns the indices where such runs begin. If no such runs are found, return null.
function findConsecutiveRuns(input:Array):Array
Example: [1, 2, 3, 5, 10, 9, 8, 9, 10, 11, 7] would return [0, 4, 6, 7]
My JS skills are a bit rusty, here is my attempt at this...
var numArray = [1, 2, 3, 5, 10, 9, 8, 9, 10, 11, 7];
var newNumArray = [];
for(var i = 1; i < numArray.length; i++) {
if ((numArray[i] - numArray[i-1] != 1) || (numArray[i] + numArray[i+1] !=1) {
return 0;
}
else {
newNumArray.push(numArray[i]);
}
}
alert(newNumArray);