Skip to content

Instantly share code, notes, and snippets.

@travisperson
Created January 8, 2012 02:31
Show Gist options
  • Save travisperson/1576915 to your computer and use it in GitHub Desktop.
Save travisperson/1576915 to your computer and use it in GitHub Desktop.
FizzBuzz
// 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