// 手写forEachArray.prototype.myForEach=function(callback, thisArg){if(this==null){thrownewTypeError('this is null or not defined');}if(typeof callback !=="function"){thrownewTypeError(callback +' is not a function');}const arr =this;let len = arr.length;let count =0;for(let i =0; i < len; i++){if(arr[i]){callback.call(thisArg, arr[i], count, arr);
count++;}}}
map
// 手写mapArray.prototype.myMap=function(callback, thisArg){if(this==null){thrownewTypeError('this is null or not defined');}if(typeof callback !=="function"){thrownewTypeError(callback +' is not a function');}let res =[];const arr =this;let len = arr.length;let count =0;for(let i =0; i < len; i++){if(arr[i]){
res[count]=callback.call(thisArg, arr[i], count, arr);
count++;}}return res;}
filter
// 手写filterArray.prototype.myFilter=function(callback, thisArg){if(this==null){thrownewTypeError('this is null or not defined');}if(typeof callback !=="function"){thrownewTypeError(callback +' is not a function');}let res =[];const arr =this;let len = arr.length;for(let i =0; i < len; i++){if(arr[i]&&callback.call(thisArg, arr[i], i, arr)){
res.push(arr[i])}}return res;}
reduce
// 手写reduceArray.prototype.myReduce=function(callback, initVal){if(this==undefined){thrownewTypeError('this is null or not defined');}if(typeof callback !=="function"){thrownewTypeError(callback +' is not a function');}if(this.length ===0){thrownewTypeError('Reduce of empty array with no initial value');}const arr =this;let len = arr.length;var total = initVal;let count =0for(let i =0; i < len; i++){if(arr[i]){
total =callback.call(this, total, arr[i], count, arr)
count++;}}return total;}