王洪莹
王洪莹
面试题 应该尽量简单吧 ```js var arr = [ ["a", "aa", "aaa", "aaaa"], ["b", "bb", "bbb"], ["a", "ab", "aba"], ["a", "aa", "aab"] ] function arrToTreeArr(arr = []) { let map = new...
```js var x='abc345efgabcab' x.replace(/[a-c]/g, '') x.replace(/([0-9])/g, '[$1]') x.replace(/([0-9])/g, ($0, $1) => $1*2) ```
```js var arr = [1, [2, [3, 4]]]; function flatten(arr) { var result = []; for (var i = 0, len = arr.length; i < len; i++) { if (Array.isArray(arr[i]))...
深度遍历 、 广度遍历 ```js function test (node) { let result = [node] let index = 0 while(index < result.length) { let children = result[index].children result.push(...children) index++ } return result }...
reutnr fn1() + Math.floor(fn1() / 2); 😂
```js function memoize(fn) { return new Proxy(fn, { cache: new Map(), apply(target, thisArg, argsList) { let cacheKey = argsList.toString(); if (!this.cache.has(cacheKey)) { this.cache.set(cacheKey, target.apply(thisArg, argsList)); } return this.cache.get(cacheKey); } });...
```js JSON.stringify(x, function replacer(key, value) { if (key === "pos") { return undefined; } return value; }) ``` 再JSON.parse 下
```js function test (arr) { let resultMap = new Map(); arr.forEach((item, index) => { if (!resultMap.has(item)) { resultMap.set(item, []); } resultMap.get(item).push(index) }) return [...resultMap].sort((a, b) => (b[1].length - a[1].length)); }...
十进制 转 36进制 (36).toString(36) 36进制 转 10进制 parseInt('10', 36)
```js function getUidData(str) { let result = []; String(str).replace(/uid=[^0-9]*([0-9]*)/g, ($0, $1) => result.push($1)); return result; } ```