👋
Welcome to Leetcoderoulette Roulette
Roulette class that returns a random value similar to a roulette table.
Installing
Using npm:
$ npm install @leetcoderoulette/roulette
Example
note: CommonJS usage
In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require()
use the following approach:
const Roulette = require('@leetcoderoulette/roulette');
// Roulette.<method> will now provide autocomplete and parameter typings
Creating a new Roulette object and getting problems
const roulette = new Roulette(["Hello", "World"]);
const values = roulette.values; // Returns ["Hello", "World"]
const value = roulette.pop(); // Returns either "Hello" or "World"
Adding a new set
roulette.values = ["New", "Problems"];
const values = roulette.values; // Returns ["New", "Problems"]
Roulette API
A roulette object can be made by passing in an array of values to Roulette
.
Roulette(values, options?)
// Create a new Roulette object.
new Roulette(["value1", "value2"]);
Instance methods
The available instance methods are listed below.
roulette.pop()
get roulette.values()
set roulette.values(values)
TypeScript
Roulette includes TypeScript definitions and a type guard for roulette errors.
let roulette: Roulette<string> = new Roulette(["Hello", "World"]);
const values: string[] = roulette.values; // Returns ["Hello", "World"]
const value: string = roulette.pop(); // Returns "Hello" or "World"
roulette.values = ["New", "Problems"];
🤝 Contributing
Contributions, issues and feature requests are welcome.
Feel free to check issues page if you want to contribute.
Check the contributing guide.
Author
- Website: Leetcode Roulette
📝 License
Copyright © 2022 Leetcode Roulette.
This project is MIT licensed.