Is this a valid use of forEach()?
Adding each of the items in an array to the result. This is what I tried.
function sum(array) {
var result = 0;
result += forEach(array);
return result;
}
The way I know that works is such
function sum(numbers) {
var total = 0;
forEach(numbers, function (number) {
total += number;
});
return total;
}
show(sum([1, 10, 100]));
No comments:
Post a Comment