This is probably basic, but I don't understand how javascript is processing this.
I have a mixed array of numbers and numbers in string form. The following formula doesn't work when the lead item is in string form. The reduce method ends up returning a concatenated string instead of a sum.
function sumMix(x) {
return x.reduce((acc, value) => acc + Number(value));
}
sumMix(['5', '0', 9, 3, 2, 1, '9', 6, 7])
Why isn't Number() successfully converting the item to number format when its the first item in the array? Why does it work fine so long as the first item is already a number type?
Its not a problem creating a solution in another way, but I don't understand why reduce won't work in this case.