Binary function arity

Angelos Chalaris · 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]

Recommended snippets

  • 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.