Created
March 28, 2020 00:55
-
-
Save Nicknyr/38d5465af343545d82b105c8ffcdd946 to your computer and use it in GitHub Desktop.
CodeSign - Even Digits Only
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
| /* | |
| Check if all digits of the given integer are even. | |
| Example | |
| For n = 248622, the output should be | |
| evenDigitsOnly(n) = true; | |
| For n = 642386, the output should be | |
| evenDigitsOnly(n) = false | |
| */ | |
| function evenDigitsOnly(n) { | |
| // Turn integers into array of strings | |
| let arrOfStrings = n.toString().split(''); | |
| // Turn array of strings into array of integers | |
| let arrayOfNumbers = arrOfStrings.map(Number); | |
| // Check if every element is even or not | |
| let answer = arrayOfNumbers.every((num) => { | |
| return num % 2 == 0; | |
| }) | |
| return answer; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment