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

pin-generator-1-cazaph

v0.0.7

Published

A library that generates random PIN codes

Downloads

4

Readme

Coding Challenge Guidelines

  • You can choose any programming language (we’d suggest choosing your strongest)
  • You can use the internet, but please don’t look up or copy an existing solution—we want to see how you work
  • This isn’t a race, but please track your time so you can tell us how long it took you
  • Please don’t spend any longer than 90 minutes total

Evaluation Criteria

Write a library for generating random PIN codes. You probably know what a PIN code is; it’s a short sequence of numbers, often used as a passcode for bank cards.

  • The library should export a function that returns a batch of 1,000 PIN codes in random order
  • Each PIN code in the batch should be unique
  • Each PIN should be:
  • 4 digits long
  • Two consecutive digits should not be the same (e.g. 1156 is invalid)
  • Three consecutive digits should not be incremental (e.g. 1236 is invalid)
  • The library should have automated tests.

Technologies

Setup

  1. Install dependencies
npm install

#or

yarn install

Run tests

npm run test

#or

yarn test

Install the library

npm install pin-generator-1-cazaph

#or

yarn add pin-generator-1-cazaph

https://www.npmjs.com/package/pin-generator-1-cazaph

Usage

Generate a batch of 1,000 PIN codes in random order

import {generatePins, isValidPin} from "pin-generator-1-cazaph";

const pins = generatePins();
console.log(pins);
// ['pin1', 'pin2', 'pin3', ...]

console.log(isValidPin("7801")); // true
console.log(isValidPin("1236")); // false
console.log(isValidPin("1156")); // false
console.log(isValidPin("0023")); // false
console.log(isValidPin("1199")); // false

API

generatePins(count?: number): string[]

This function allows you to generate random pins according to the count. The count is optional and defaults to 1,000.

isValidPin(pin: string, pins?:[]): boolean

This function validates if the pin is valid. To be valid the pin should:

  • Have 4 digits long,
  • Not contain consecutive digits
  • Not contain digits that are incrementally increasing.
  • Not be included in the pins array.

The pins parameter is optional and defaults to an empty array.

hasSameConsecutiveDigits(numbers: number[]): boolean

This function checks if the numbers has consecutive digits.

isIncremental(numbers: number[]): boolean

This function checks if the numbers contains 3 more numbers incrementally increasing. e.g. 1239

shuffle(arr: any[]): any[]

This function takes a list of numbers and returns a shuffled version of the same list.

License

The MIT License (MIT). Please see License File for more information.