叶家伟
叶家伟
```js Array.prototype.spliceLike = function(start, num, ...params) { return [...this.slice(0, start), ...params, ...this.slice(start + num)] } ```
```js 思想来源:借鉴vue diff源码 function intersectionArr(...params) { let itemCountMap = []; params.forEach(arr => { arr.forEach(item => { itemCountMap[item] = (itemCountMap[item] ? itemCountMap[item] : 0) + 1; }) }) let itArr =...
```js function deal() { const cards = []; for(let i = 0; i < 52; i++) { cards.push(i); } cards.sort((a, b) => (Math.ceil(Math.random() * 52) - 1) - b); return...
@zxmajunhong 算法题不是用来实际用的,是来练你的逻辑思维和语法熟练度的,理论和实际是两码事,理论好了实操才会更好,没有理论支持,实操能好到哪儿去?最多也是搬砖工
```js 思想:排序+双端遍历 即可实现 function findPart(arr) { arr = arr.sort((a, b) => a - b); const sum = arr.reduce((pre, cur) => pre + cur, 0); const part = Math.floor(sum / 3);...
```js function isContainNode(a, b) { return a.contains(b); } function isContainNode(a, b) { const p = b.closest('.a'); if(p != null && p.isEqualNode(a)) { return true } return false; } ```
```js 考的就是你对对象引用熟不熟 function arrToObj(arr) { arr = Array.from(arr, (v, k) => Object.assign({}, v)); // 基于引用来的做的,这里的arr需要拷贝一下 let root = []; arr.forEach(item => { if(item.parentId == 0) { root.push(item); }else { const...
```js function getMonths(times) { let start = new Date(times[0]), end = new Date(times[1]); const months = []; while(start
```js function randomColor() { const r = (Math.floor(Math.random() * 255)).toString(16); const g = (Math.floor(Math.random() * 255)).toString(16); const b = (Math.floor(Math.random() * 255)).toString(16); const a = (Math.random()).toString(16).slice(2, 4); console.log(a); return `#`...
```js 熟写发布订阅模式可以锻炼你的增删改查能力 class PubSub { sid = 0 topicList = {} constructor(...tops) { this.topicList = Object.fromEntries(tops.map(item => [item, []])); } isValidTopic(topic){ return Object.keys(this.topicList).includes(topic) } sub(topic, target) { const isValidTopic =...