Skip to content

Instantly share code, notes, and snippets.

@stanistan
Created August 6, 2012 22:24
Show Gist options
  • Save stanistan/3279040 to your computer and use it in GitHub Desktop.
Save stanistan/3279040 to your computer and use it in GitHub Desktop.
Messing around with fizzbuzz
var fizzbuzz = function(n) {
return [ { m: 3, word: 'Fizz'}, { m: 5, word: 'Buzz'} ]
.map(function(c) { return !(n % c.m) ? c.word : ''; })
.join('') || n;
};
for (var i = 1; i < 101; i++) {
console.log(fizzbuzz(i));
}
(defn fizzbuzz [n]
(let [fb (->> [{:m 3 :word "Fizz"} {:m 5 :word "Buzz"}]
(map (fn [t] (if (zero? (mod n (:m t))) (:word t) "")))
(reduce str))]
(if (empty? fb) n fb)))
(map fizzbuzz (range 1 101))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment