I am solving Sums of Parts challenge by codewars platform. I think that I solved the challenge but I still need to deal with arrays have thousands of elements.
My code:
function partsSums(ls) {
let length = ls.length;
let newArr = [ls.reduce((acc, cur) => acc + cur, 0)];
for (let i = 0; i < length; i++) {
ls.splice(0, 1);
newArr.push(ls.reduce((acc, cur) => acc + cur, 0))
}
return newArr;
}
console.log(partsSums([1, 2, 3, 4, 5, 6]))`
The link of the challenge: