I have a decently tricky javascript data manipulation problem that I am struggling with. I have the following array of data:
var myArray = [8, 13, 11, 17, 5, 13, 13];
And I would like to map this array into an array of equal length, where each value in the new array is equal to the difference between the array's previous value at that spot, and the next lowest value in the previous array. This is wordy, but for example, I want the output to be:
var newArray = [3, 2, 3, 4, 5, 0, 0];
3 in the first element is (8 - 5), where 8 is the array's previous value in the first slot, and 5 is the next lowest value in the previous array. 2 in the second element is (13 - 11), ... etc.
I'm not particularly caring how to handle ties (for example there are 2 values of 13 in the original array), so long as exactly one instance of 13 is replaced with (13 - next lowest value), and all other instances of 13 are replaced with zero (13 - 13 essentially).
Thanks!