MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / createArrayMethod

Function createArrayMethod

lib/web/polyfill.js:237–268  ·  view source on GitHub ↗
(type)

Source from the content-addressed store, hash-verified

235 * 6 -> findIndex
236 */
237function createArrayMethod(type){
238 var isMap = type == 1
239 , isFilter = type == 2
240 , isSome = type == 3
241 , isEvery = type == 4
242 , isFindIndex = type == 6
243 , noholes = type == 5 || isFindIndex;
244 return function(callbackfn/*, that = undefined */){
245 var O = Object(assertDefined(this))
246 , that = arguments[1]
247 , self = ES5Object(O)
248 , f = ctx(callbackfn, that, 3)
249 , length = toLength(self.length)
250 , index = 0
251 , result = isMap ? Array(length) : isFilter ? [] : undefined
252 , val, res;
253 for(;length > index; index++)if(noholes || index in self){
254 val = self[index];
255 res = f(val, index, O);
256 if(type){
257 if(isMap)result[index] = res; // map
258 else if(res)switch(type){
259 case 3: return true; // some
260 case 5: return val; // find
261 case 6: return index; // findIndex
262 case 2: result.push(val); // filter
263 } else if(isEvery)return false; // every
264 }
265 }
266 return isFindIndex ? -1 : isSome || isEvery ? isEvery : result;
267 }
268}
269function createArrayContains(isContains){
270 return function(el /*, fromIndex = 0 */){
271 var O = toObject(this)

Callers 1

polyfill.jsFile · 0.85

Calls 6

ObjectFunction · 0.85
assertDefinedFunction · 0.85
ctxFunction · 0.85
toLengthFunction · 0.85
fFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected