Created
January 9, 2023 07:41
-
-
Save ChrisDobby/0ed230753b3bf053dd6d77ee04b573bd to your computer and use it in GitHub Desktop.
Given a number, sum every second digit in that number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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