Last active
July 17, 2020 01:17
-
-
Save clsource/5e03f493f96223717a357c7c040407b0 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
| (() => { | |
| const numbers = [0, 3, 5, 10, 15, 20, 25, 30]; | |
| const FIZZ = 3; | |
| const FIZZ_WORD = "Fizz"; | |
| const BUZZ = 5; | |
| const BUZZ_WORD = "Buzz"; | |
| const checkModuleIsZero = (numerator, denominator) => { | |
| return numerator % denominator === 0; | |
| }; | |
| const checkStateFizz = (num) => { | |
| return checkModuleIsZero(num, FIZZ); | |
| }; | |
| const checkStateBuzz = (num) => { | |
| return checkModuleIsZero(num, BUZZ); | |
| }; | |
| let state; | |
| numbers.forEach(number => { | |
| state = null; | |
| if(checkStateFizz(number)) { | |
| state = FIZZ_WORD; | |
| if(checkStateBuzz(number)) { | |
| state += BUZZ_WORD; | |
| } | |
| } | |
| if(!state && checkStateBuzz(number)) { | |
| state = BUZZ_WORD; | |
| } | |
| console.log({number, state}); | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment