Complete the square sum function so that it squares each number passed into it and then sums the results together. For example, for [1, 2, 2]
it should return 9
because 1^2 + 2^2 + 2^2 = 9
.
I managed to do the task but I did not understand why i had to add 0 at the end to pass the test. If i remove that 0,it doesn't pass. Can anyone please explain it ? I am newbie.
function numbers (numbers) {
return numbers.map((num) => num ** 2).reduce((initValue, currentValue) => initValue + currentValue,0)
}