js实现filter
Array.prototype.fakeFilter = function fakeFilter(fn, context) { if (typeof fn !== "function") { throw new TypeError(`${fn} is not a function`); } let arr = this; let temp = []; for (let i = 0; i < arr.length; i++) { let result = fn.call(context, arr[i], i, arr); if (result) temp.push(arr[i]); } return temp; };