UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

31 lines (30 loc) 725 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.flip = void 0; /** * Creates a function that invokes `func` with arguments reversed. * * @since 5.12.0 * @category Function * @param func The function to flip arguments for. * @returns Returns the new flipped function. * @see [[reverse]] * @example * * ```js * const flipped = flip((...args) => args) * * flipped('a', 'b', 'c', 'd') * // => ['d', 'c', 'b', 'a'] * ``` */ function flip(func) { if (typeof func !== "function") { throw new TypeError("Expected a function"); } return function (...args) { return func.apply(this, args.reverse()); }; } exports.flip = flip; exports.default = flip;