UNPKG

jsmodern

Version:

An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.

17 lines 505 B
export const shuffle = { label: 'shuffle', fn: function arrayShuffle() { const ctx = this; const len = ctx.length; if (len > 1) { const cloned = ctx.slice(); ctx.length = 0; while (cloned.length > 0) { const rand = Math.floor(Math.random() * cloned.length); const shifted = cloned.splice(rand, 1)[0]; ctx.push(shifted); } } }, }; //# sourceMappingURL=shuffle.js.map