Skip to content

Instantly share code, notes, and snippets.

@piotrjaw
Created February 26, 2019 13:53
Show Gist options
  • Save piotrjaw/2a1b7e12c6cdd31f07062d5fdcf3359b to your computer and use it in GitHub Desktop.
Save piotrjaw/2a1b7e12c6cdd31f07062d5fdcf3359b to your computer and use it in GitHub Desktop.

Revisions

  1. piotrjaw created this gist Feb 26, 2019.
    16 changes: 16 additions & 0 deletions flatten.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    const flatten = (arr) => {
    const result = [];

    const _flatten = (arrayOrValue) => {
    if (Array.isArray(arrayOrValue)) {
    arrayOrValue.map(_flatten);
    } else {
    result.push(arrayOrValue);
    }
    };

    arr.map(_flatten);
    return result;
    };

    export default flatten;