Yay for FizzBuzz!

This commit is contained in:
AJ ONeal 2010-06-26 10:54:40 -06:00
commit d51959eda0
5 changed files with 58 additions and 0 deletions

9
README Normal file
View File

@ -0,0 +1,9 @@
FizzBuzz
========
An array of the usual suspects - Hello World, FizzBuzz, Fibonacci, more to come...
TODO
----
* Echo Client / Server
* Ajax Chat

16
fibonacci.js Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env node
"use strict";
var sys = require('sys');
(function () {
var seq = [];
function fibonacci(a, b) {
seq.push(a);
if (a >= 100) {
seq.push(b);
return;
}
fibonacci(b, a+b);
}
fibonacci(0,1);
sys.print(seq.join(', ') + "\n");
}());

21
fizzbuzz.js Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env node
"use strict";
var sys = require('sys');
(function () {
var i, n;
for (i = 1; i <= 100; i += 1) {
n = false;
if (0 === (i % 3)) {
n = true;
sys.print("Fizz");
}
if (0 === (i % 5)) {
n = true;
sys.print("Buzz");
}
if (true === n) {
sys.print("\n");
}
}
}());

6
fizzbuzz.rb Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env ruby
(1..100).each do |x|
print "Fizz" if 0 == (x % 3)
print "Buzz" if 0 == (x % 5)
print "\n" if 0 == (x % 3) || 0 == (x % 5)
end

6
hello.js Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env node
"use strict";
var sys = require('sys');
(function () {
sys.print("Hello World!\n");
}());