Binary function arity

JavaScript, Function · Oct 18, 2020

Creates a function that accepts up to two arguments, ignoring any additional arguments.

  • Call the provided function, fn, with the first two arguments given.
const binary = fn => (a, b) => fn(a, b);
['2', '1', '0'].map(binary(Math.max)); // [2, 1, 2]

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this

  • Function arity

    JavaScript, Function

    Creates a function that accepts up to n arguments, ignoring any additional arguments.

  • Unary function arity

    JavaScript, Function

    Creates a function that accepts up to one argument, ignoring any additional arguments.

  • Bind object method

    JavaScript, Function

    Creates a function that invokes the method at a given key of an object, optionally prepending any additional supplied parameters to the arguments.