LuoYu

Results 12 comments of LuoYu

```js function Node(value){ this.value = value this.next = null } function Queue(){ this.dummyHead = new Node(-1) } Queue.prototype.add = function(node) { var curr = this.dummyHead while (curr.next){ curr = curr.next...

```js function Node(value){ this.value = value this.next = null } function Queue(){ this.dummyHead = new Node(-1) } Queue.prototype.add = function(node) { var curr = this.dummyHead while (curr.next){ curr = curr.next...

```js function debounce(func, wait, immediate) { var timeout, result var d = function(){ var context = this var args = arguments if(timeout)clearTimeout(timeout) if(immediate){ var call = !timeout timeout = setTimeout(function(){...

```js function all(promiseList) { return new Promise((resolve, reject) => { if(!promiseList || !promiseList.length) return resolve([]) let count = 0 let length = promiseList.length let result = [] for (let i...

```js function all(promiseList) { return new Promise((resolve, reject) => { if(!promiseList || !promiseList.length) return resolve([]) let count = 0 let length = promiseList.length let result = [] for (let i...

```js let input = [ { id: 1, val: "学校", parentId: null, }, { id: 2, val: "班级1", parentId: 1, }, { id: 3, val: "班级2", parentId: 1, }, {...

```js var PENDING = 'pending'; var REJECTED = 'rejected'; var FULFILLED = 'fulfilled'; function MyPromise(executor){ this.status = PENDING this.onFulfilled = [] this.onRejected = [] this.reason = null this.value = null...

```js function get(arr){ let stack = [] let n = arr.length let res = new Array(n).fill(-1) for(let i = 0; i < n; i++){ while(stack.length && arr[stack[stack.length - 1]] <...

```js function EventEmitter(){ this.caches = {} } EventEmitter.prototype.on = function(type, event){ if(!this.caches[type]) this.caches[type] = [] this.caches[type].push(event) return this } EventEmitter.prototype.off = function(type, event){ if(!this.caches[type]) return this.caches[type] = this.caches[type].filter(item => item...

```js function proxyArray(arr){ return new Proxy(arr, { get(target, key){ if(key >= 0) return target[key] let len = target.length return target[len + (key % len)] } }) } var arr =...