随笔分类 -  JavaScript

JS 基础扩展
摘要:源码实现,直接发代码 function deepClone(obj, map=new WeakMap()) { // WeakMap 弱引用,不用时及时回收 if(!obj) return obj; if(obj instanceof Date) {return new Date(obj)} if( 阅读全文
posted @ 2021-07-08 10:26 guogrant 阅读(33) 评论(0) 推荐(0) 编辑
摘要:1,原型链继承 父: SuperType 子: SubType SubType.prototype = new SuperType(); // 继承了SuperType 实现的本质是重写原型对象;即重写了子类的原型 prototype ,创建SuperType实例,并将该实例赋值给SubType.p 阅读全文
posted @ 2020-11-28 14:39 guogrant 阅读(78) 评论(1) 推荐(0) 编辑
摘要:普通版本 function doubleSort(arr) { let len = arr.length - 1; for(let i=0; i<arr.length; i++) { // 第一层循环遍历总次数 for(let j=0; j<len-i; j++) { // 第二层循环 从左往右 j 阅读全文
posted @ 2020-07-06 17:34 guogrant 阅读(178) 评论(0) 推荐(0) 编辑
摘要:// 创建堆 function CreateHeap(MaxSize,MaxData) { this.MaxSize = MaxSize; this.Heap = new Array(); this.Heap[0] = MaxData // 定义" 哨兵 " 为大于堆中所有可能元素的值 this.i 阅读全文
posted @ 2020-06-30 16:21 guogrant 阅读(189) 评论(0) 推荐(0) 编辑
摘要:// 树根 function Tree(data,left,right) { this.data = data this.left = left this.right = right this.leftNode = Tree.leftNode this.rightNode = Tree.rightN 阅读全文
posted @ 2020-06-29 12:39 guogrant 阅读(192) 评论(0) 推荐(0) 编辑
摘要:function Node(coef,expon) { this.coef = coef; // 系数 this.expon = expon; // 指数 this.next = null; } List.attach = function(node) { let current = this.he 阅读全文
posted @ 2020-06-27 01:42 guogrant 阅读(419) 评论(0) 推荐(0) 编辑
摘要:/** * Initialize your data structure here. */ var MyStack = function() { this.inQueue = []; this.outQueue = []; }; /** * Push element x onto stack. * 阅读全文
posted @ 2020-06-24 11:26 guogrant 阅读(76) 评论(0) 推荐(0) 编辑
摘要:/** * Initialize your data structure here. */ var MyQueue = function() { this.stack1 = []; this.stack2 = []; }; /** * Push element x to the back of qu 阅读全文
posted @ 2020-06-24 11:24 guogrant 阅读(80) 评论(0) 推荐(0) 编辑
摘要:Queue.isEmpty = function() { return (this.front == this.rear); } Queue.isFull = function() { return ((this.rear + 1) % this.MaxSize == this.front); } 阅读全文
posted @ 2020-06-23 17:28 guogrant 阅读(599) 评论(0) 推荐(0) 编辑
摘要:回文数判断 function isParmse(str) { if(typeof str !== 'string') return false; let i = 0,j = str.length - 1; while(i < j) { if (str.charAt(i) !== str.charAt 阅读全文
posted @ 2020-05-08 11:21 guogrant 阅读(356) 评论(0) 推荐(0) 编辑
摘要:什么是扁平化 ? 意思是将多维数组转化为一维数组。 话不多说,直接上代码。 直接方式 arr.flat(Infinity); For 循环 + 递归 function flat(arr) { let dd = []; for(let i=0; i<arr.length; i++) { if(Arra 阅读全文
posted @ 2020-05-08 10:52 guogrant 阅读(190) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示