Back to Freecodecamp

Challenge 211: Array Sum

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/6994cff2290543b3aec9f510.md

latest834 B
Original Source

--description--

Given an array of numbers, return the sum of all the numbers.

--hints--

sumArray([1, 2, 3, 4, 5]) should return 15.

js
assert.equal(sumArray([1, 2, 3, 4, 5]), 15);

sumArray([42]) should return 42.

js
assert.equal(sumArray([42]), 42);

sumArray([5, -2, 7, -3]) should return 7.

js
assert.equal(sumArray([5, -2, 7, -3]), 7);

sumArray([203, 145, -129, 6293, 523, -919, 845, 2434]) should return 9395.

js
assert.equal(sumArray([203, 145, -129, 6293, 523, -919, 845, 2434]), 9395);

sumArray([0, 0]) should return 0.

js
assert.equal(sumArray([0, 0]), 0);

--seed--

--seed-contents--

js
function sumArray(numbers) {

  return numbers;
}

--solutions--

js
function sumArray(numbers) {

  return numbers.reduce((a, c) => c + a, 0);
}