Socket
Socket
Sign inDemoInstall

bizzfuzz

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bizzfuzz

Extendable FizzBuzz Library in Javascript (LOL)


Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

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); // Returns Fizz

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); // Returns 11 with default settings

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); // Returns true
bizzFuzz.isNextAfter(100); // Returns false

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?

// From lib/options.js

module.exports = options = {
  // How many should be incremented with each step
  add: 1,

  // What BizzFuzz starts at 
  startsAt: 1,

  // What BizzFuzz ends at
  endsAt: 100,

  // First number
  firstNumber: 3,

  // Second number
  secondNumber: 5,

  // Function for test for first number
  firstNumberTest: function(num, firstNumber) {
    return num % firstNumber === 0;
  },

  // Function for test for second number
  secondNumberTest: function(num, secondNumber) {
    return num % secondNumber === 0;
  },

  // What to show if only the first test succeeds
  firstTestSuccess: "fizz",

  // What to show if only the second test succeeds
  secondTestSuccess: "buzz",

  // What to show if both tests succeed
  bothSuccess: "fizzbuzz",

  // What to show if no tests succeed
  noSuccess: function(num) {
    return String(num);
  }
}

BizzFuzz can be changed by giving an object to BizzFuzz to override these defaults.

// This example starts at 10, adds 10 for each step, and stops at 70
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;

// Recursive FizzBuzz function
function fizzbuzz(number) {
  console.log(bizzFuzz.valueFor(number));

  if (bizzFuzz.isNextAfter(number)) {
    fizzbuzz(bizzFuzz.nextAfter(number));
  }
}

// Start the FizzBuzz
fizzbuzz(bizzFuzz.startingNumber());

Keywords

FAQs

Package last updated on 21 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc