Return to Blog entry
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.