Travis build: 1666

This commit is contained in:
30secondsofcode
2019-12-31 09:38:53 +00:00
parent 21b0ab5c65
commit 2344523e5b
15 changed files with 93 additions and 97 deletions

View File

@ -15,15 +15,10 @@ const weightedSample = (arr, weights) => {
let roll = Math.random();
return arr[
weights
.reduce((acc, w, i) =>
i === 0 ? [w] : [...acc, acc[acc.length - 1] + w],
[]
)
.findIndex((v, i, s) =>
roll >= (i === 0 ? 0 : s[i - 1]) && roll < v
)
.reduce((acc, w, i) => (i === 0 ? [w] : [...acc, acc[acc.length - 1] + w]), [])
.findIndex((v, i, s) => roll >= (i === 0 ? 0 : s[i - 1]) && roll < v)
];
}
};
```
```js