Skip to content

Instantly share code, notes, and snippets.

@gupta-ji6
Created May 26, 2018 10:57
Show Gist options
  • Select an option

  • Save gupta-ji6/77723eeb0f9aeb83ac665c25860e1313 to your computer and use it in GitHub Desktop.

Select an option

Save gupta-ji6/77723eeb0f9aeb83ac665c25860e1313 to your computer and use it in GitHub Desktop.

Revisions

  1. gupta-ji6 created this gist May 26, 2018.
    22 changes: 22 additions & 0 deletions copyWithoutReference.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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;
    };