A collection of pretty useful helper functions.
const randomBool = (singleDigitProbability: number): boolean => {
// ...
};
First, import it.
import { randomBool } from "helperfunc";
Or, in CommonJS syntax:
const { randomBool } = require("helperfunc");
randomBool()
takes in a single digit number as it’s only parameter.
WANRING:: randomBool()
ONLY allows single digit numbers. If you use a number above 10, it will return null and console.error out.
Here’s an example:
const booleanButRandom = randomBool(9); // 90% of true, 10% of false
console.log(booleanButRandom); // Would be true or false