BizzFuzz
Extendable FizzBuzz Library in Javascript (LOL). It provides a way for calculating the value for a specific number and affordances for finding the next number.
API
valueFor
Function for getting the FizzBuzz value of a number
bizzFuzz = new BizzFuzz;
bizzFuzz.valueFor(3);
nextAfter
Function for getting the next number in the sequence (useful when incrementing by something other than the default)
bizzFuzz = new BizzFuzz;
bizzFuzz.nextAfter(10);
isNextAfter
Function for returning a boolean of whether or not there is a next number after the one supplied
bizzFuzz = new BizzFuzz;
bizzFuzz.isNextAfter(10);
bizzFuzz.isNextAfter(100);
Options
BizzFuzz comes with defaults that for the conditions of the question:
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".
See Why Can't Programers.. Program?
module.exports = options = {
add: 1,
startsAt: 1,
endsAt: 100,
firstNumber: 3,
secondNumber: 5,
firstNumberTest: function(num, firstNumber) {
return num % firstNumber === 0;
},
secondNumberTest: function(num, secondNumber) {
return num % secondNumber === 0;
},
firstTestSuccess: "fizz",
secondTestSuccess: "buzz",
bothSuccess: "fizzbuzz",
noSuccess: function(num) {
return String(num);
}
}
BizzFuzz can be changed by giving an object to BizzFuzz to override these defaults.
bizzFuzz = BizzFuzz({
add: 10,
startsAt: 10,
endsAt: 70
});
See tests for more examples.
Example FizzBuzz
Below is an example using BizzFuzz to do a FizzBuzz.
var BizzFuzz = require('bizzfuzz');
var bizzFuzz = new BizzFuzz;
function fizzbuzz(number) {
console.log(bizzFuzz.valueFor(number));
if (bizzFuzz.isNextAfter(number)) {
fizzbuzz(bizzFuzz.nextAfter(number));
}
}
fizzbuzz(bizzFuzz.startingNumber());