Within my array of arrays, I am trying to subtract all inner arrays a - b and then sum the results. For example: [[10,0],[3,5],[5,8]] would result in 10 - 0 = 10, 3 - 5 = -2, 5 - 8 = -3, giving a total of 10 + (-2) + (-3) = 5;
Here is my attempt:
var el;
return array.reduce((a, b) => a - b );
However, my result came out as NaN. Now I understand that trying to subtract an array from another array was not a good idea. I know how to achieve this using a 'for' loop or similar method, but my question is:
How can I accomplish this using reduce or other "modern" method?
Thank you for your help.
PS. Please excuse any errors in my English skills ;)