ikun

Results 18 comments of ikun

```javascript const splitNumber = num => { const base = `${Number(num)}`; const [integer, decimal] = base.split("."); let result = ""; let currentNumber = ""; for (let index = integer.length -...

```javascript const printTags = () => { const body = document.getElementsByTagName("body")[0]; const tags = new Map(); const dp = node => { if (node.tagName.startsWith("S") || node.tagName.startsWith("H")) { if (tags.has(node.tagName)) {...

```javascript const reduce = (source, callback, initValue) => { let acc = initValue; for (let index = 0; index < source.length; index++) { acc = callback(acc, source[index], index, source); }...

```javascript const sleep = (wait = 1000) => { return new Promise(resolve => { const timer = setTimeout(() => { resolve(); clearTimeout(timer); }, wait); }); }; ```

ES6写法 ```javascript const mergePromise = async ajaxArray => { const result = []; const createTask = async executer => { const currentResult = await executer(); result.push(currentResult); }; for (let index...

```javascript const parseQueryString = url => { const [_, params] = url.split("?"); const result = {}; params.split("&").map(item => { const [key, value] = item.split("="); result[key] = value; }); return result;...

```javascript String.prototype.trim = function () { if (this.length left) { if (that[right] !== " ") { break; } right--; } console.log(`DEBUG: after trim left: ${left} right: ${right}`); return that.slice(left, right...

```javascript const jsonStringfy = source => { let result = ""; const cache = new Map(); const dp = data => { const values = []; Object.keys(data).forEach(key => { if...