0

I found a function for the running sum of an array in javascript.

const runningSum = function(nums) {
  return nums.map((acc = 0, num => acc += num));
};

For my understanding and according to the definition from MDN is acc := currentValue and num:= Index. But how does that work with the arrow function inside the parameters? I appreciate any help or explantions

Flowly
  • 23
  • 4
  • I think you are confusing reduce and map. What you shared makes little sense. – Evert Dec 30 '22 at 08:43
  • 2
    Note the extra set of parenthesis. It's a really unintuitive way of writing: ```const runningSum = function(nums) { acc = 0; return nums.map(num => acc += num); };``` (Note that implicit globals are awful too). – Quentin Dec 30 '22 at 08:43
  • 1
    @Evert It makes sense, it's just a very unorthodox way (and arguably wrong way) of writing this… – deceze Dec 30 '22 at 08:44

0 Answers0