![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
js
/*马猴烧酒*/
朝更厉害的方向迈进
展开
-
手动实现一个find,findIndex
手动实现一个find, findIndex昨天又没写- -|今天这也算不了两个,等会儿再写个吧,写完汇个总。。。const array1 = [5, 12, 8, 130, 44];Array.prototype.myFind = function(callback) { for(let c of this){ if(callback(c)){ return c; } }}Array.prototype.myFindIndex = function(callback){ for原创 2021-02-14 12:14:55 · 329 阅读 · 0 评论 -
手动实现一个every,fill
手动实现一个Array的every,fill方法昨天在写copyWithin方法的时候出bug了,最后这个方法测试的时候一直有问题,按文档上我应该是对的,但浏览器却报错,故这个方式先放放。昨天没写,今天补一个everyconst array1 = [1, 30, 39, 29, 10, 13];Array.prototype.myEvery = function(callback) { if(this.length === 0){ return true; } for(let c of t原创 2021-02-12 19:53:33 · 172 阅读 · 0 评论 -
手动实现一个concat
手动实现一个Array的concat方法let num1 = [1,2,3];let num2 = ['a','b'];Array.prototype.myConcat = function(arr) { for(let c of arr){ this.push(c); }return this;}console.log(num1.myConcat(num2))原创 2021-02-10 20:58:32 · 235 阅读 · 2 评论 -
手动实现一个filter
手动实现一个数组的filter方法let arr = [1,2,3,4,5,6];Array.prototype.myFilter = function(callback){ let result = []; for(let i=0;i<this.length;i++){ if(callback(this[i])){ result.push(this[i]); } } return result;}let arr1 = arr.myFilter(function(item原创 2021-02-09 10:03:23 · 215 阅读 · 1 评论