fizzbuzz = function (n) { return (n%3?'':'fizz')+(n%5?'':'buzz')||n } Mike 16th July, 2008 12:14 (UTC)

Hmm, giving up trying to format this….but

fizzbuzz_style_game = function (rules) {
    return function (n) {
       var result = '';
       for (var divisor in rules) 
            result += n%divisor?"":rules[divisor];
       return result || n}
}
my_buzz = fizzbuzz_style_game({
    3:'fizz',
    5:'buzz',
    7:'is',
    11:'a',
    13:'simple',
    17:'yet',
    19:'interesting',
    23:'game'
})

Good software can be changed easily. Parameterisation is the most powerful way to do this.