Skip to content

Instantly share code, notes, and snippets.

@usagi
Created April 11, 2012 03:11
Show Gist options
  • Select an option

  • Save usagi/2356610 to your computer and use it in GitHub Desktop.

Select an option

Save usagi/2356610 to your computer and use it in GitHub Desktop.
var fizz_buzz = {
range : {
begin : 1,
end : 100,
},
test : function(target_value, test_value) {
return target_value % test_value === 0;
},
test_sets : [
{ value: 3, word: 'Fizz!', },
{ value: 5, word: 'Buzz!', },
],
};
for(var n = fizz_buzz.range.begin; n <= fizz_buzz.range.end; n = n + 1) {
var words = '';
for(var key in fizz_buzz.test_sets) {
var test = fizz_buzz.test_sets[key];
if ( fizz_buzz.test(n, test.value) )
words = words + test.word;
}
if ( words === '' )
words = String(n);
console.log('n:' + n + ' "' + words + '"');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment