Skip to content

Instantly share code, notes, and snippets.

@gupta-ji6
Created May 26, 2018 10:57
Show Gist options
  • Select an option

  • Save gupta-ji6/77723eeb0f9aeb83ac665c25860e1313 to your computer and use it in GitHub Desktop.

Select an option

Save gupta-ji6/77723eeb0f9aeb83ac665c25860e1313 to your computer and use it in GitHub Desktop.
function copy(o) {
var output, v, key;
output = Array.isArray(o) ? [] : {};
for (key in o) {
v = o[key];
output[key] = (typeof v === "object") ? copy(v) : v;
}
return output;
}
const shuffle = (array) => {
let currentIndex = array.length, temp, randomIndex;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temp = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temp;
}
let arr = copy(array);
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment