Let's try and break it down.
(sum => el => sum += el) , is equivalent to:
const mySumFunction = (sum) => {
const addToSum = (el) => {
sum += el;
return sum;
}
return addToSum;
}
This is a function that takes in a parameter - a starting sum. The sum parameter is also local variable within the function's scope.
When you call mySumFunction, it returns another function that adds to the local scoped variable sum and returns the total sum so far.
In effect, it creates a "function with memory" that returns the sum of everything that has been passed into it so far.
You can test this out as follows:
cumilativeSum = mySumFunction(0)
console.log(v(1)) // returns 1
console.log(v(1)) // returns 2
console.log(v(4)) // returns 6
Now let's look at the code as a whole.
let runningSum = nums => nums.map((sum => el => sum += el)(0));
The entire snippet passed into the map function: (sum => el => sum += el)(0) creates a "sum function with memory" that starts at 0, as we figured out above.
We're passing each of the numbers in an array to it and creating an array with the cumulative sum.