Closed DaZhaoLis closed 6 years ago
function curry(fn,arity = fn.length) { // Q: why need IIFE ? return (function nextCurried(prevArgs){ return function curried(nextArg){ var args = [ ...prevArgs, nextArg ]; if (args.length >= arity) { return fn( ...args ); } else { return nextCurried( args ); } }; })( [] ); }
function curry(fn,arity = fn.length) { // Q: why need IIFE ? return (function nextCurried(prevArgs){ return function curried(nextArg){ var args = [ ...prevArgs, nextArg ]; if (args.length >= arity) { return fn( ...args ); } else { return nextCurried( args ); } }; })( [] ); }