poppydani

Results 9 comments of poppydani

```javascript function format(str) { const reverse = str.toString().split('').reverse().join(''); return reverse.replace(/(\d{3})/g, '$1,').replace(/\,$/g, '').split('').reverse().join(''); } ```

```javascript Promise.retry = function (promiseFun, times = 5) { return new Promise((resolve, reject) => { const getResult = () => { times --; promiseFun().then(res => { console.log(res) resolve(res); }).catch(error =>...

const min = arr.filter(v => v > 0).sort((a, b) => a - b)[0] const index = arr.findIndex(v => v === min);

``` function multiRequest(urls, maxNum) { return new Promise((resolve, reject) => { const result = []; // 输出结果 let count = 0; // 当前有多少个请求 let finished = 0; // 已经完成的请求数 const...

```javascript Array.prototype._splice = function (start, delCount, ...addItems) { const arr = this; const res = []; const left = arr.slice(0, start); const right = arr.slice(start + delCount) const remove =...

`function test() { list.reduce(async (p, x)=> { await p; const res = await square(x) console.log(res) }, Promise.resolve()) }`

``` javascript function test() { list.reduce(async (p, x)=> { await p; const res = await square(x) console.log(res, +new Date() / 1000) }, Promise.resolve()) } ```

```javascript Array.prototype._map = function (fn) { const arr = this; const res = []; for (let i = 0; i < arr.length; i++) { const ele = arr[i]; res[i] =...

```javascript function intersect(...args) { const flattened = args.reduce((res, arr) => { return res.concat(arr); }, []); return [...new Set(flattened)].filter((v) => args.every((arr) => arr.includes(v)) ); } ```