Skip to content

Instantly share code, notes, and snippets.

@sethetter
Created February 17, 2014 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethetter/9052531 to your computer and use it in GitHub Desktop.
Save sethetter/9052531 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
// http://upfrontwichita.com/challenges/3
/**
* fizzBuzz
*/
var fizzBuzz = function(low, high) {
var result = [];
if (typeof high === 'undefined') {
if (low % 5 == 0 && low % 3 == 0) {
result.push('fizzbuzz');
} else if (low % 3 == 0) {
result.push('fizz');
} else if (low % 5 == 0) {
result.push('buzz');
} else {
result.push(low);
}
} else {
for (var i = low; i < high; i++) {
var mThree = (i % 3) == 0
, mFive = (i % 5) == 0
, both = mThree && mFive;
if (both) {
result.push('fizzbuzz');
} else if (mThree) {
result.push('fizz');
} else if (mFive) {
result.push('buzz');
} else {
result.push(i);
}
}
}
return result;
};
module.exports = fizzBuzz;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment