I'm working with a JavaScript array and need some help. The array looks something like this:
var exampleArr1 = [5,4,1,-2,-5,-7,5,1,2,-3,2,4...];
var exampleArr2 = [-5,-4,1,2,5,7,-5,1,2,3,-2,4...];
My goal is to create a function that can detect sign changes in the array and return the position along with the numbers involved in the change. So, the output should look like ['index','num1','num2']
as shown in the example below.
function getSignChange(exampleArr1){
...
return someArray;
}
The expected output should be:
[
[2,1,-2], //index = 2 change from 1 to -2
[5,-7,5], //index = 5 change from -7 to 5
[8,2,-3], //index = 8 change from 2 to -3
]
If anyone has any advice or guidance on how to achieve this, it would be greatly appreciated. Thank you!