//rewrite this sum function so that it uses a loop instead of recursion
function sum(l) {
if (l.length === 0) {
return 0;
} else {
return l[0] + sum(l.slice(1));
}
}
console.log(`sum([1,2,3,4]) = ${sum([1,2,3,4])}`); //should be 10