This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defined first due to TDZ | |
let weighted = (...weightMap) => weightMap | |
.map(({0: value, 1: weight}) => new Array(weight).fill(value)) | |
.reduce((acc, current) => [...acc, ...current]); | |
let random = (array) => array[Math.floor(Math.random() * array.length)]; | |
// You can generate a weighted array |