Added utils dir.

This commit is contained in:
ThePendulum 2021-11-15 15:55:22 +01:00
parent 57b837cd60
commit cb82fc9969
1 changed files with 17 additions and 0 deletions

17
src/utils/shuffle.js Normal file
View File

@ -0,0 +1,17 @@
'use strict';
function shuffle(unshuffled, limit = 10) {
const shuffled = unshuffled;
for (let i = shuffled.length - 1; i > 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
const temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled.slice(0, limit);
}
module.exports = shuffle;