Last active
June 17, 2019 22:15
-
-
Save anchowake/ad7d4fc0c65816545e037672db870b49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Find the twos | |
| // Given an integer like this: | |
| // 2468122368128146226989812 | |
| // Implement a function called `findTheTwos` that return the total number of number two in the integer | |
| // findTheTwos(246812236812) = 7 | |
| const num = 246812236812; | |
| const targetNum = 2; | |
| function findTheTwos(int, target) { | |
| let totalOcurrences = 0; | |
| while (int > 0) { | |
| if (int % 10 === target) { | |
| totalOcurrences += 1; | |
| } | |
| int = Math.floor(int / 10); | |
| } | |
| return totalOcurrences; | |
| } | |
| console.log(findTheTwos(num, targetNum)); | |
| // Restrictions | |
| // You CAN NOT use strings in any form |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment