Last active
October 15, 2016 15:15
-
-
Save Roboe/a181936cec7312ae4ac2 to your computer and use it in GitHub Desktop.
h4ckademy
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
var fizzbuzz = function(n) { | |
var ret = ""; | |
if(n%3 === 0) { | |
ret+= "Fizz"; | |
} | |
if(n%5 === 0) { | |
ret += "Buzz"; | |
} | |
return ret || n; | |
}; | |
/* tddbin.com */ | |
describe('FizzBuzz kata', function() { | |
/* | |
Write a program that prints the numbers from 1 to 100. | |
But for multiples of three print “Fizz” instead of the number and for the | |
multiples of five print “Buzz”. For numbers which are multiples of both three | |
and five print “FizzBuzz”. | |
*/ | |
it('returns Fizz if multiple of 3 but not of 5', function() { | |
var result = 'Fizz'; | |
assert.equal(fizzbuzz(3), result); | |
assert.equal(fizzbuzz(9), result); | |
assert.equal(fizzbuzz(3333), result); | |
}); | |
it('returns Buzz if multiple of 5 but not of 3', function() { | |
var result = 'Buzz'; | |
assert.equal(fizzbuzz(5), result); | |
assert.equal(fizzbuzz(10), result); | |
assert.equal(fizzbuzz(5555), result); | |
}); | |
it('returns FizzBuzz if multiple of 3 and 5', function() { | |
var result = 'FizzBuzz'; | |
assert.equal(fizzbuzz(0), result); | |
assert.equal(fizzbuzz(15), result); | |
assert.equal(fizzbuzz(30), result); | |
assert.equal(fizzbuzz(1500), result); | |
}); | |
it ('returns number if not multiple of 3 nor 5', function(){ | |
assert.strictEqual(fizzbuzz(1), 1); | |
assert.strictEqual(fizzbuzz(44), 44); | |
assert.strictEqual(fizzbuzz(808), 808); | |
}); | |
}); | |
for (var i = 1; i <= 100; i++) { | |
console.log(fizzbuzz(i)); | |
} |
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
var getWithDefault = function(obj, prop, defaultValue) { | |
return obj[prop] || defaultValue; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment