Created
January 8, 2012 02:31
-
-
Save travisperson/1576915 to your computer and use it in GitHub Desktop.
FizzBuzz
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
// FizzBuzz | |
// Saw this problem on hacker news and decided to write it out | |
// Originally wrote it with console.log and ran into a few problems | |
// so I came back and added the `write` method to console. | |
var util = require('util') | |
argv = process.argv | |
// No line break to stdout | |
console.write = function () { | |
process.stdout.write(util.format.apply(this, arguments)) | |
} | |
function FizzBuzz(x) { | |
if(!x) return x | |
FizzBuzz(x - 1) | |
if (x%3 === 0) console.write("Fizz") | |
if (x%5 === 0) console.write("Buzz") | |
if (x%3 && x%5) console.write(x) | |
console.write("\n") | |
} | |
FizzBuzz(argv[2] || 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment