exportfunctionmap(fn,thisArg){constO=Object(this)constlen=O.lengthif(!(fninstanceofFunction))thrownewTypeError(`${fn} is not a function`)constA=newArray(len)for(letk=0;k<len;k++){constPk=k.toString()constkPresent=O.hasOwnProperty(Pk)if(kPresent){constkValue=O[i]constmappedValue=fn.call(thisArg,kValue,i,O)Object.defineProperty(A,Pk,{value:mappedValue,writable:true,enumerable:true,configurable:true})}}returnA}
But most of that is lost unless you actually write the upper loop inline, because unlike the built in methods it gets deoptimized if you call the utility with many different fn functions. Especially when some of them throw.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I wish JS runtimes did better inlining and monomorphization.
Then you could have your own utilities like
Which beats out what the spec method does:
But most of that is lost unless you actually write the upper loop inline, because unlike the built in methods it gets deoptimized if you call the utility with many different
fn
functions. Especially when some of them throw.