Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created February 4, 2014 18:02
Show Gist options
  • Save trikitrok/44bc6e27a92cc6dff1ad to your computer and use it in GitHub Desktop.
Save trikitrok/44bc6e27a92cc6dff1ad to your computer and use it in GitHub Desktop.
var fizzbuzz = function (numbers) {
var fizzbuzz_one = function (number) {
var res = "";
if (number % 3 == 0)
res += "Fizz";
if (number % 5 == 0)
res += "Buzz";
if (res == "")
res = String(number);
return res;
};
return (function f(acc, rest) {
if (rest.length == 0)
return acc;
else if (rest.length == 1)
return acc + fizzbuzz_one(rest[0]);
else
return f (acc + fizzbuzz_one(rest[0]) + " ", rest.slice(1));
})("", numbers);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment