Skip to content

Instantly share code, notes, and snippets.

@btholt
Created July 29, 2014 13:14
Show Gist options
  • Save btholt/d6f895856eb39e750f30 to your computer and use it in GitHub Desktop.
Save btholt/d6f895856eb39e750f30 to your computer and use it in GitHub Desktop.
Function JavaScript FizzBuzz
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