Skip to content

Instantly share code, notes, and snippets.

@ins77
Created April 25, 2020 11:23
Show Gist options
  • Select an option

  • Save ins77/c89ecdb0981d8a35716909b05f7f469c to your computer and use it in GitHub Desktop.

Select an option

Save ins77/c89ecdb0981d8a35716909b05f7f469c to your computer and use it in GitHub Desktop.

Revisions

  1. ins77 created this gist Apr 25, 2020.
    14 changes: 14 additions & 0 deletions magic.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    const magic = (...rest) => {
    const sum = rest.reduce((acc, current) => acc + current, 0);
    const inner = (...args) => {
    return magic(inner.valueOf(), ...args);
    };

    inner.valueOf = () => sum;

    return inner;
    };

    magic(5, 2, -9).valueOf();

    magic(5, 2, -8)(4) + 2;