Skip to content

Instantly share code, notes, and snippets.

@laispace
Created August 31, 2015 12:28
Show Gist options
  • Select an option

  • Save laispace/59179ca4f1644cca856f to your computer and use it in GitHub Desktop.

Select an option

Save laispace/59179ca4f1644cca856f to your computer and use it in GitHub Desktop.

Revisions

  1. laispace created this gist Aug 31, 2015.
    15 changes: 15 additions & 0 deletions randomArray.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    function randomArray (array) {
    if (array.length === 1) {
    return array;
    } else {
    var len = array.length;
    var index = ~~(Math.random() * len);
    var item = array.splice(index, 1);
    return item.concat(randomArray(array));
    }

    }
    var array = [1,2,3,4,5,6];
    var result = randomArray(array);
    console.log(result)