Last active
February 15, 2018 17:12
-
-
Save TheGreatRambler/3e1685e470c4f4b820301559ecf29b56 to your computer and use it in GitHub Desktop.
Use this function to randomly ruin a array by splitting it up and inserting those chunks in random places.
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 randomlySplitArray(inputarray, chunksize, numofloops) { | |
| function randomint(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| var temparray = inputarray; | |
| for (var q = 0; q < numofloops; q++) { | |
| var start = randomint(0, inputarray.length - chunksize); | |
| var othertemp = temparray.splice(start, chunksize); | |
| var index = randomint(0, temparray.length - chunksize - 1); | |
| // https://stackoverflow.com/questions/7032550/javascript-insert-an-array-inside-another-array | |
| temparray = temparray.slice(0, index).concat(othertemp).concat(temparray.slice(index)); | |
| } | |
| return temparray; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment