UNPKG

shared-libs

Version:

Shared Libs oferece funções diversas de conversão de objeto que podem ser usadas em qualquer projeto.

24 lines (17 loc) 522 B
const shuffle = (value) => { let currentindex = value.length, temporaryValue, randomindex; // While there remain elements to shuffle... while (0 !== currentindex) { // Pick a remaining element... randomindex = Math.floor(Math.random() * currentindex); currentindex -= 1; // And swap it with the current element. temporaryValue = value[currentindex]; value[currentindex] = value[randomindex]; value[randomindex] = temporaryValue; } return value; } module.exports = { shuffle }