This file contains 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
//get a random weighted element in O(n) time and O(n) space | |
const randomWeightedElement = (elems, weightFn) => { | |
if(!elems || !elems.length) return; | |
const weighted = []; | |
let sum = 0; | |
for (let elem of elems) { | |
const weight = weightFn(elem); | |
if (weight > 0) { | |
sum += weight; | |
weighted.push({ elem, boundary: sum }); |
This file contains 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
// a work in progress... | |
const autoBind = require('auto-bind'); | |
/** | |
* A Tree of decision making executable nodes. | |
*/ | |
class Tree { | |
/** | |
* @constructor {String} name. |
This file contains 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
function Productable(arr) { | |
const self = { | |
array: arr.map(e => Array.isArray(e) ? e : [e]), | |
product: (otherArr) => { | |
const newArray = []; | |
self.array.forEach(e => { | |
otherArr.forEach(oe => { | |
newArray.push([...e, oe]); | |
}); | |
}); |