Skip to content

Instantly share code, notes, and snippets.

@carl-parrish
Last active December 25, 2017 16:14
Show Gist options
  • Save carl-parrish/e7294641065ffef4d05c268b36c5837c to your computer and use it in GitHub Desktop.
Save carl-parrish/e7294641065ffef4d05c268b36c5837c to your computer and use it in GitHub Desktop.

Revisions

  1. carl-parrish renamed this gist Dec 25, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. carl-parrish renamed this gist Dec 25, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. carl-parrish revised this gist Dec 25, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    ```js
    /********************
    ** Write some code, that will flatten an array
    ** of arbitrarily nested arrays of integers
    @@ -12,4 +13,5 @@ function flatten(source){
    return answer;
    }
    const myArray = [[1,2,[3]],4];
    console.log(flatten(myArray)); // [1,2,3,4]
    console.log(flatten(myArray)); // [1,2,3,4]
    ```
  4. carl-parrish revised this gist Feb 17, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    var answer = [];

    function flatten(source){
    source.forEach(val => Array.isArray(val)? flatten(val) : answer.push(val));
    source.map(val => Array.isArray(val)? flatten(val) : answer.push(val));
    return answer;
    }
    const myArray = [[1,2,[3]],4];
  5. carl-parrish revised this gist Feb 17, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions js
    Original file line number Diff line number Diff line change
    @@ -11,5 +11,5 @@ function flatten(source){
    source.forEach(val => Array.isArray(val)? flatten(val) : answer.push(val));
    return answer;
    }

    console.log(flatten(myArray));
    const myArray = [[1,2,[3]],4];
    console.log(flatten(myArray)); // [1,2,3,4]
  6. carl-parrish revised this gist Sep 18, 2016. No changes.
  7. carl-parrish revised this gist Sep 18, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    /********************
    ** Write some code, that will flatten an array
    ** of arbitrarily nested arrays of integers
    ** into a flat array of integers.
    ** e.g. [[1,2,[3]],4] -> [1,2,3,4]
    ************************/

    var answer = [];

    function flatten(source){
  8. carl-parrish created this gist Sep 17, 2016.
    8 changes: 8 additions & 0 deletions js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    var answer = [];

    function flatten(source){
    source.forEach(val => Array.isArray(val)? flatten(val) : answer.push(val));
    return answer;
    }

    console.log(flatten(myArray));