Created
May 26, 2018 10:57
-
-
Save gupta-ji6/77723eeb0f9aeb83ac665c25860e1313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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