1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
function ribArr(arr) { const set = new Set() // 使用集合特性去重 arr.forEach(item => set.add(item)) // 获得集合迭代对象 const setInterator = set.values() let item = setInterator.next() // 清空形参 arr = [] // 进行迭代对象 while (!item.done) { arr.push(item.value) item = setInterator.next() } return arr.sort((a, b) => b - a) }
console.log(ribArr([12, 2, 2, 234, 4, 6, 6, 7, 6]))
function getRandomArr(num, max, min) { const arr = []; while (num--) { arr.push(Math.round(Math.random() * (max - min)) + min) } return arr.sort((a, b) => a - b) }
console.log(getRandomArr(10, 100, 10))
function transformHump(params) { const paramsArr = params.split('-') params = paramsArr[0] for (let index = 1; index < paramsArr.length; index++) { const item = paramsArr[index] params += item.charAt(0).toUpperCase() + item.slice(1) } return params } console.log(transformHump('get-element-by-id'))
function transformQuery(url) { if (/\?.*$/.test(url)) { const query = {} const queryArr = url.slice(url.indexOf('?') + 1).split('&') queryArr.forEach(item => { item = item.split('=') console.log(item[1]) query[item[0]] = `${item[1]}` }) return JSON.stringify(query) } return JSON.stringify(null) }
console.log(transformQuery('http://item.taobao.com/item.htm?a=1&b=2&c=&d=xxx&e'))
function getAppearMaxChar(str) { let appearMaxArr = []; for (let index = 0; index < str.length; index++) { const params = str.match(new RegExp(str[index], 'g')); if (appearMaxArr.length < params.length) appearMaxArr = params } return { char: appearMaxArr[0], count: appearMaxArr.length } }
console.log(getAppearMaxChar('hjbjhbio888joi78g8f7f6rdr98hu'))
function transformRMB(num) { const str = String(num) let transformStr = '' const fristStr = str.substr(0, str.length % 3 || 3) for (let index = str.length - 3; index > 0; index -= 3) { transformStr = ',' + str.substr(index, 3) + transformStr } transformStr = fristStr + transformStr return transformStr }
transformRMB(123456789)
|