npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bizzfuzz

v1.0.4

Published

Extendable FizzBuzz Library in Javascript (LOL)

Downloads

10

Readme

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());