Created
February 17, 2014 15:21
-
-
Save sethetter/9052531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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