You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// plus functionconstplus=(...args)=>{returnargs.reduce((accu,curr)=>{returnaccu+curr},0)}// mult functionconstmult=(...args)=>{returnargs.reduce((accu,curr)=>{returnaccu*curr},1)}// proxy factoryconstcreateProxyFactory=(fn)=>{letcache={}return(...args)=>{letargsId=args.join(',')if(Object.keys(cache).indexOf(argsId)>=0){console.log('read from cache')returncache[argsId]}returncache[argsId]=fn.apply(this,args)}}constproxyPlus=createProxyFactory(plus)constproxyMult=createProxyFactory(mult)letm1=console.log(proxyMult(2,3,4))// 24letm2=console.log(proxyMult(2,3,4))// read from cache 24letp1=console.log(proxyPlus(2,3,4))// 9letp2=console.log(proxyPlus(2,3,4))// read from cache 9
The text was updated successfully, but these errors were encountered: