Last active
July 31, 2017 20:34
-
-
Save itotallyrock/2587b366dd8623b64b7d2efa074c2e84 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
function getNum(input) { | |
let conditions = [{num: 3, word: 'Fizz'}, {num: 5, word: 'Buzz'}] | |
return conditions.map(({num, word}) => { | |
return input % num === 0 ? word : '#' | |
}).join('').replace(/#+/, input).replace(/(\d+)?([A-z]+)(\d+)?/g, '$2') | |
} |
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
function getNum(num) { | |
return num % 3 === 0 ? (num % 5 === 0 ? 'FizzBuzz' : 'Buzz') : (num % 5 === 0 ? 'Fizz' : num.toString()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding more condtions is easy, just add another object to the conditions variable.
For example: