beary
beary
``` javascript const A = [1, 3, 5, 6, 7]; const B = [1, 3, 5, 6, 8]; function judge(A, B) { let str1 = A.sort((a, b) => a -...
``` javascript function process(cur, sum = 0) { return cur === 0 ? sum : process(cur - 1, sum + cur); } console.log(process(100)); ```
``` javascript class Schedular { constructor(limit) { this.limit = limit; this.queue = []; this.runCounts = 0; } add(time, order) { const mypromise = () => { return new Promise((resolve, reject)=>{...
``` javascript class EventEmitter{ constructor(){ this.event = {}; } on(name, callback){ if(this.event[name]){ this.event[name].push(callback); }else{ this.event[name] = [callback]; } } off(name, callback){ if(!this.event[name]) return; if(!callback) this.event[name] = []; this.event[name] = this.event[name].filter((item)=>{...
``` javascript function transform(num){ let res = ''; while(num){ let val = num % 2; num = Math.floor(num / 2); res = val + res; } return res; } console.log(transform(10));...
``` javascript // 1. 简单版数组乱序 function generateRandomV1(num) { return num.sort(() => Math.random() - 0.5); } // 2. 复杂版 function generateRandom(len = 10, min = 1, max = 30) { if...
``` javascript const arr = ['ab', 'c', 'ab', 'd', 'c']; let map = new Map(); for (let i = 0; i < arr.length; i++) { map.set(arr[i], (map.get(arr[i]) || 0) +...
``` Function.prototype._myCall = function(thisArg, ...args) { thisArg = thisArg !== null && thisArg !== undefined ? Object(thisArg) : window; let fn = Symbol(); thisArg[fn] = this; const res = thisArg[fn](...args);...
> ```js > // 该代码为上面同学提交的,虽然考虑到了边界条件,更加严谨,但是是有问题的,会使始终指向全局对象window > // 问题就出在这个箭头函数,因为箭头函数的特性,会无法获得到正确的this,即调用call的函数 > // !!!处理方式:更改为function(){}即可 > Function.prototype._myCall = (thisArg, ...args) => { > thisArg = > thisArg !== null && thisArg !== undefined ?...
``` javascript const obj1 = { a: "11", b: { c: "22" } }; const obj2 = { a: "11", b: { c: "22" } }; function isEqual(obj1, obj2) {...