Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active December 22, 2020 17:19
Show Gist options
  • Select an option

  • Save ericelliott/e03558b5d5f8d1c82842f7744a2f3e89 to your computer and use it in GitHub Desktop.

Select an option

Save ericelliott/e03558b5d5f8d1c82842f7744a2f3e89 to your computer and use it in GitHub Desktop.

Revisions

  1. ericelliott revised this gist Jan 30, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion filter.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    const filter = (fn, arr) => arr.reduce((newArr, item) => {
    return fn(item) ? [...newArr, item] : newArr;
    return fn(item) ? newArr.concat([item]) : newArr;
    }, []);
  2. ericelliott revised this gist Jan 28, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions filter.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    const filter = (fn, arr) => arr.reduce((newArr, item) => {
    if (fn(item)) return [...newArr, item];
    return newArr;
    return fn(item) ? [...newArr, item] : newArr;
    }, []);
  3. ericelliott created this gist Jan 28, 2017.
    4 changes: 4 additions & 0 deletions filter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    const filter = (fn, arr) => arr.reduce((newArr, item) => {
    if (fn(item)) return [...newArr, item];
    return newArr;
    }, []);