Skip to content

Instantly share code, notes, and snippets.

@tripdog
Created June 17, 2021 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripdog/141d5ccc60565277a672403b3f411f2d to your computer and use it in GitHub Desktop.
Save tripdog/141d5ccc60565277a672403b3f411f2d to your computer and use it in GitHub Desktop.
Create a function that takes in a list and find the sum of all the numbers

Create a function that takes in a list and find the sum of all the numbers.

const arr =[1, 2, 3]

function getSum(list) {
  let sum = 0;
  for (let i = 0; i < list.length; i++) {
    sum = sum + list[i];
  }
  return sum;
}
console.log(getSum([arr]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment