Last active
August 6, 2022 03:38
-
-
Save kylelong/fa41e9b68ee452926f9d64d09ea7457a to your computer and use it in GitHub Desktop.
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 numberOfOnes = (num) => { | |
let sum = 0; | |
for(let i = 0; i <= num; i++){ | |
sum += i.toString().split("").filter(number => number === '1').length; | |
} | |
return sum; | |
} | |
console.log(numberOfOnes(14)); //7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment