UNPKG

shuffle-es6

Version:

Fisher-Yates shuffle with injectable random-number-generator as ES6 module

15 lines (14 loc) 286 B
function h(n, t = Math.random) { for (var f = n.length - 1; f >= 0; f--) { var e = Math.floor(t() * (f + 1)), o = n[e]; n[e] = n[f], n[f] = o; } } function l(n, t = Math.random) { var f = n.slice(); return h(f, t), f; } export { l as shuffle, h as shuffleInplace };