Skip to content

Instantly share code, notes, and snippets.

@DercilioFontes
Created February 15, 2018 19:53
Show Gist options
  • Select an option

  • Save DercilioFontes/7442012104a8efa4bacbb13fc33c82f4 to your computer and use it in GitHub Desktop.

Select an option

Save DercilioFontes/7442012104a8efa4bacbb13fc33c82f4 to your computer and use it in GitHub Desktop.
Sum Array of Numbers - Lighthouse Labs
function sumItems(array) {
// Sum all the numbers in the array
let sum = 0;
for (const item of array) {
if (Array.isArray(item)) {
sum += sumItems(item);
} else {
sum += item;
}
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment