3.6k words 3 mins.

# instanceof 原理 instanceof 运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链上。 语法 object instanceof constructor 参数 object(某个实例对象) 、 constructor(某个构造函数) 本质上 instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。 function _instanceof(target, origin) { // 这里需要加层判断 if (typeof target !==...
6.8k words 6 mins.

# fill 原理 # 使用 for 实现 Array.prototype._fill = function (value = [], start = 0, end = this.length) { //start 大于数组长度 或 end 大于数组长度返回自身 不然下面的 this [i] 会改变自身长度 if (start > this.length || end > this.length) return this //start < 0 或 end < 0 则是按 length + start|end 来计算,MDN 有介绍...
2.8k words 3 mins.

# every 原理 # 使用 for 实现 Array.prototype._every = function (callback) { for (let i = 0; i < this.length; i++) { if(!callback(this[i], i, this)) return false } return true}const array = ['稚名真白', '樱岛麻衣', '蝶祈']const flag =...
3.4k words 3 mins.

# forEach 原理 # 使用 for 实现 const array = ['稚名真白', '樱岛麻衣', '蝶祈']Array.prototype._forEach = function (callback) { for (let i = 0; i < this.length; i++){ callback(this[i], i, this) }}array._forEach((value, index, array) => {...
2k words 2 mins.

# 优先级队列结构 优先级队列的特点 我们知道,普通的队列插入一个元素,数据会被放在后端。并且需要前面所有的元素都处理完后才会处理前面的数据。 但是优先级队列,再插入一个元素的时候会考虑该数据的优先级。和其他数据优先级 进行比较 比较完成后,可以得出这个元素在队列中正确的位置 其他处理方式,和基本队列的处理方式一样。 优先级队列主要考虑的问题: 每个元素不再只是一个数据,而且包含数据的优先级 # Example 生活中的优先级队列例子 比如某些家庭在吃饭时,老人优先级更高,先动筷子,其次是父母,最后才是小孩。 你正在吃饭,突然非常想去五谷轮回之所,于是你就去了。 Example...
1.7k words 2 mins.

# 队列结构(Queue) 队列是一个简单的数据结构,它是一个 允许在一端进行插入操作,而在另一端进行删除操作的线性表 。队列遵循先进先出(FIFO, First-In-First-Out)的特征,和栈(LIFO, Last In First Out)刚好相反。 队列,它是一种受限的线性表 受限之处在于它只允许在表的前端 (front) 进行删除操作 而在表的后端 (rear) 进行插入操作 生活中类似的队列结构 比如电影院、商城、奶茶店排队 优先排队的人,优先处理 # 实现队列 封装一个队列实现下面的击鼓传花 // 封装队列类function Queue()...
1.6k words 1 mins.

# 预览效果 #triangle { width: 0; height: 0; border: 50px solid transparent; border-left: 50px solid #4ad3e2; border-right: 50px solid #4ad3e2; border-top: 50px solid #ffb1a3; border-bottom: 50px solid #f9cb8f; } [class^=triangle] { margin: 30px; width: 0; height: 0; border: 50px solid...
1.4k words 1 mins.

# 预览效果 [class^=triangle] { margin: 50px auto; width: 20px; height: 20px; transform: rotate(45deg); } .triangle-left { border-left: 4px solid #4ad3e2; border-bottom: 4px solid #4ad3e2; } .triangle-right { border-right: 4px solid #4ad3e2; border-top: 4px solid #4ad3e2; } .triangle-top { border-left:...
850 words 1 mins.

# Dec2Bin Example Example 1: 输入:n = 10输出:1010解释:将十进制转换为二进制Example 2: 输入:n = 15输出:1111解释:将十进制转换为二进制# Solving Ideas function dec2bin(decNumber) { const stack = new Array() //decNumber > 0 停止循环 while (decNumber > 0) { // 将每次取模的数存入栈中 stack.push(decNumber % 2) // 同时向下取 / 2 的值...
2.9k words 3 mins.

# 预览效果 body { --bgc: #353b48; background-color: var(--bgc); } .container { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: space-around; width: 100%; } .container .btn { width: 35vw; height: 60px; border: 3px solid; background: none; color: var(--c); cursor:...