Skip to content

Instantly share code, notes, and snippets.

@borislavstoychev
Created May 4, 2021 21:50
Show Gist options
  • Select an option

  • Save borislavstoychev/b7d8e78b221b4c172f3afcec96e7856e to your computer and use it in GitHub Desktop.

Select an option

Save borislavstoychev/b7d8e78b221b4c172f3afcec96e7856e to your computer and use it in GitHub Desktop.
function foo(num) {
let evenSum = 0;
let oddSum = 0;
for (const n of String(num)) {
Number(n) % 2 == 0 ? evenSum += Number(n) : oddSum += Number(n)
}
return ` Odd sum = ${oddSum}, Even sum = ${evenSum}`;
}
console.log(foo(1000435))
console.log(foo(3495892137259234))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment