GolderBrother

Results 44 comments of GolderBrother

// 1. 防抖:不停的触发事件,只执行最后一次 // 指的是某个函数在某段时间内,无论触发了多少次回调,都只执行最后一次。假如我们设置了一个等待时间 3 秒的函数,在这 3 秒内如果遇到函数调用请求就重新计时 3 秒,直至新的 3 秒内没有函数调用请求,此时执行函数,不然就以此类推重新计时。 function debounce(fn, wait = 500, immediate = false) { let timer = null, result = null; return...

```js function currying(fn, args = []) { return function temp(...innerArgs) { if (innerArgs.length > 0) { // 收集后面传入的参数 args = [...args, ...innerArgs]; // 返回函数供后面可以继续调用 return temp; } else { const...

```js Promise.all = function (promises) { return new Promise((resolve, reject) => { if (!Array.isArray(promises)) { throw new Error('argument must be a array'); } // 用来记录Promise成功的次数 let resolveCount = 0, //...

```js function arrayToTree(array = []) { // 获取祖先节点 const root = array.shift(); const tree = { id: root.id, val: root.val, children: toTree(root.id, array) }; return tree; } function toTree(parentId, array...

```js var obj = { a: "12", b: "23", first: { c: "34", d: "45", second: { 3: "56", f: "67", three: { g: "78", h: "89", i: "90" }...

```js var obj = { a: "12", b: "23", first: { c: "34", d: "45", second: { 3: "56", f: "67", three: { g: "78", h: "89", i: "90" }...

```js function repeat(func, times, wait) { function sleep(fn, wait, args) { return new Promise((resolve, reject) => { setTimeout(() => { try { const res = typeof fn === 'function' &&...

```js function repeat(func, times, wait = 1000) { // TODO return async function (...args) { function delay(fn, wait) { return new Promise((resolve, reject) => { setTimeout(() => { try {...

var lengthOfLongestSubstring = function (s = '') { let map = new Map(); let i = -1, res = 0, len = s.length; for(let j = 0; j < len;...