Skip to content

Instantly share code, notes, and snippets.

@ChrisDobby
Created January 9, 2023 07:41
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 ChrisDobby/0ed230753b3bf053dd6d77ee04b573bd to your computer and use it in GitHub Desktop.
Save ChrisDobby/0ed230753b3bf053dd6d77ee04b573bd to your computer and use it in GitHub Desktop.
Given a number, sum every second digit in that number.
const sumEveryOther = (num: number) =>
num
.toString()
.split('')
.reduce((total, digit, index) => ((index + 1) % 2 === 0 ? total + parseInt(digit) : total), 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment