Published
Edited
Feb 4, 2018
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Multiply elements by its weight and create new array
weight = function(arr) {
return [].concat(...arr.map((obj) => Array(Math.ceil(obj.weight * 100)).fill(obj)));
}
Insert cell
Insert cell
pick = function(arr) {
let weighted = weight(arr);
return weighted[Math.floor(Math.random() * weighted.length)]
}
Insert cell
Insert cell
{
while (true) {
yield new Promise(resolve => {
setTimeout(() => resolve(
pick(list)
), 500);
});
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more