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

fizzbuzz.js

v0.1.1

Published

🐝FizzBuzz solution for values n:m, w/optional divisors & text

Downloads

2

Readme

FizzBuzz.js

FizzBuzz solution for values n:m, w/optional divisors & text.

Return an array from values n:m for i, yielding [f] + [b] for value (n+i % div0) === 0 && (n+i % div1) === 0, yielding [f] for value (n+i % div0) === 0, yielding [b] for value (n+i % div1) === 0.

This solution to the FizzBuzz problem was inspired by a thread on Reddit about common frontend developer interview questions. I implemented a solution using a bodyless for-loop with heavy use of ternary operators.

This example was then turned into this Node module for even more concise code during an interview, where the developer can show his/her pragmatism and reluctance for "reinventing the wheel".

Usage

Simple usage:

$ npm install -s fizzbuzz.js

Then:

var fizzBuzz = require('fizzbuzz.js').fizzBuzz;
var results = fizzBuzz();

FizzBuzz takes optional arguments:

  • n: (Number) Start value, default: 1
  • m: (Number) End value, defalt: 100
  • f: (String) Alternative Fizz string, default 'Fizz'
  • b: (String) Alternative Buzz string, default 'Buzz'
  • div0: (Number) Alternative first divisible value, default 3
  • div1: (Number) Alternative second divisible value, default 5

This will return an array for values 1 to 100, for values divisible by 3 and 5.

var fizzBuzz = require('fizzbuzz.js').fizzBuzz;
var results = fizzBuzz(1, 100, 'Fizz', 'Buzz', 3, 5);

Returns an array with the following indexed values:

1 1
2 2
3 'Fizz'
4 4
5 'Buzz'
6 'Fizz'
7 7
8 8
9 'Fizz'
10 'Buzz'
11 11
12 'Fizz'
13 13
14 14
15 'FizzBuzz'
16 16
17 17
18 'Fizz'
19 19
20 'Buzz'
21 'Fizz'
22 22
23 23
24 'Fizz'
25 'Buzz'
26 26
27 'Fizz'
28 28
29 29
30 'FizzBuzz'
31 31
32 32
33 'Fizz'
34 34
35 'Buzz'
36 'Fizz'
37 37
38 38
39 'Fizz'
40 'Buzz'
41 41
42 'Fizz'
43 43
44 44
45 'FizzBuzz'
46 46
47 47
48 'Fizz'
49 49
50 'Buzz'
51 'Fizz'
52 52
53 53
54 'Fizz'
55 'Buzz'
56 56
57 'Fizz'
58 58
59 59
60 'FizzBuzz'
61 61
62 62
63 'Fizz'
64 64
65 'Buzz'
66 'Fizz'
67 67
68 68
69 'Fizz'
70 'Buzz'
71 71
72 'Fizz'
73 73
74 74
75 'FizzBuzz'
76 76
77 77
78 'Fizz'
79 79
80 'Buzz'
81 'Fizz'
82 82
83 83
84 'Fizz'
85 'Buzz'
86 86
87 'Fizz'
88 88
89 89
90 'FizzBuzz'
91 91
92 92
93 'Fizz'
94 94
95 'Buzz'
96 'Fizz'
97 97
98 98
99 'Fizz'
100 'Buzz'

Authors

License

MIT