Created
July 29, 2014 13:14
-
-
Save btholt/d6f895856eb39e750f30 to your computer and use it in GitHub Desktop.
Function JavaScript FizzBuzz
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
var fizzWord = function(x) { | |
if (!(x % 15)) | |
return "fizzbuzz"; | |
else if (!(x % 3)) | |
return "fizz"; | |
else if (!(x % 5)) | |
return "buzz"; | |
else | |
return x; | |
}; | |
var fizzBuzz = function(max) { | |
return Array | |
.apply(null, { length: max+1 }) | |
.map(Number.call, Number) | |
.splice(1) | |
.map(fizzWord); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment