Guest User

Untitled

a guest
Oct 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. var y = [25, 8, 7, 41, 22, 11, 2, 1000];
  2.  
  3. var randomize = function(array) {
  4. var output = [],
  5. arrLen = array.length;
  6.  
  7. for ( var i = 0; i < array.length; i++ ) {
  8. output[i] = false;
  9. }
  10.  
  11. var findSpot = function(inputVal){
  12. var potentialSpot = Math.floor(Math.random()*arrLen);
  13. if ( !output[potentialSpot] ) {
  14. output[potentialSpot] = inputVal;
  15. } else {
  16. findSpot(inputVal);
  17. }
  18. }
  19.  
  20. for ( var i = 0; i < array.length; i++ ) {
  21. findSpot(array[i]);
  22. }
  23.  
  24. return output;
  25. }
  26.  
  27. randomize(y);
Add Comment
Please, Sign In to add comment