var a = [1, 5, 7, 3];
console.log(DiffTheArray(a));
With the expected result of [4, 2, -4]
, which is the difference between every two elements of the original array, how would DiffTheArray
most concisely be implemented?
I was hoping to implement it using slices (a.slice(1) - a.slice(0,-1)
), but there doesn't seem to be a built-in way of subtracting one array from another in JS.