wens
wens
```js var data = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]; function flatDepth(arr){ return arr.reduce((total, cur)...
``` const numToReverseStr = (num) => { let result = num % 10; if (num === 0) { return '' } const newNum = Number(String(num).slice(0 ,-1)); return String(result) + numToReverseStr(newNum);...
```js // 我先来,模拟图片加载过程 function loadImg(url) { return new Promise((resolve, reject) => { const img = new Image(); img.onload = function() { console.log(url, "加载完成"); resolve(img); }; img.onerror = function() { reject(new...
``` function normalize(str) { const list = str.match(/\w+/g) function fn(list) { if(list.length === 1){ return { value: list[0] } } let res = {} const item = list.shift(); res =...
``` function moveZero(list) { let count = 0; for(let i=0;i
``` function sortColor(str) { let yellowCount = 0 return str.split('').reduce((res, cur)=>{ if(cur==='黄'){ yellowCount++ res.unshift(cur) }else if(cur==='红'){ res.splice(yellowCount,0,cur) }else if(cur==='蓝'){ res.push(cur) } return res }, []) } ```
``` const trans = (str) => { const arr = str.split(',').concat(undefined); let start = Number(arr[0]); let gap = 1; let temp = ''; let result = []; for(let i=1;i
``` // 题目描述的不是很清楚,如果三位数以上数组该如何分配?所以代码先按照100以内的数字来说 // 随机生成一个长度为count最大值为max的数组 function random(count=10, max=100){ return new Array(count).fill().map((item) => { return Math.floor(Math.random() * max) }) } function trans(array){ const mapping = array.sort((a,b) => a-b).reduce((result, cur) => {...
```js function convert(data) { return Object.keys(data).reduce((res, keys) => { const value = data[keys]; const keyList = keys.split("."); const lastKey = keyList.pop(); const objResult = keyList.reduce((obj, key) => { if (!obj[key])...