Created
December 27, 2015 16:36
-
-
Save mohamedhayibor/9609c3cbc3618e97d6c3 to your computer and use it in GitHub Desktop.
This file contains 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
var arr = [1, 2, 4, 7, 9, 6, 3]; | |
function flatten() { | |
return [].reduce.call(arguments, function(sum, val) { | |
return Array.isArray(val) ? sum.concat(flatten.apply(null, val)) : sum.concat(val); | |
}, []); | |
} | |
function shuffle (array) { | |
var temp = []; | |
while (0 !== array.length) { | |
temp.push(array.splice(Math.floor(Math.random() * (array.length -1)), 1 ) ); | |
} | |
return flatten(temp); | |
} | |
console.log(shuffle(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment