2022年3月28日

摘要: let arr = [1,2,3,4,5] let max = Math.max.apply(Array, arr) let min = Math.min.apply(Array, arr) console.log(max, min) 阅读全文
posted @ 2022-03-28 22:08 GameCat 阅读(20) 评论(0) 推荐(0) 编辑
摘要: function shuffle(arr) { for(let i = 0; i < arr.length; i++){ let randomIndex = Math.floor(Math.random() * (i + 1)) let item = arr[randomIndex] arr[ran 阅读全文
posted @ 2022-03-28 22:00 GameCat 阅读(67) 评论(0) 推荐(0) 编辑
摘要: function uniqueArr(arr) { return [...new Set(arr.flat(Infinity))] } let str = 'abccccccdddww' console.log(uniqueArr(str.split(''))) let arr = [1, [1, 阅读全文
posted @ 2022-03-28 21:47 GameCat 阅读(23) 评论(0) 推荐(0) 编辑
摘要: let str = 'abccccccdddww' function getType(variable) { return Object.prototype.toString.call(variable).replace(/\[object\s|\]/g, '') } console.log(get 阅读全文
posted @ 2022-03-28 21:22 GameCat 阅读(21) 评论(0) 推荐(0) 编辑
摘要: let str = 'abccccccdddww' function countNums(parentStr, childStr) { return parentStr.split(childStr).length - 1 } console.log(countNums(str, 'cc'))//3 阅读全文
posted @ 2022-03-28 21:12 GameCat 阅读(256) 评论(0) 推荐(0) 编辑
摘要: let str = `\nzifu_chuan chang\t` function func(str) { // 这里不去掉字符间的空格 return str.replace(/[\n\t\r\v\f]/g, '') } console.log(func(str)) 阅读全文
posted @ 2022-03-28 21:05 GameCat 阅读(506) 评论(0) 推荐(0) 编辑
摘要: let str = "zifu_chuan_chang" function func(str) { let arr = str.split('_') let resStr = arr.reduce(function(prev, cur){ let str = prev + cur.slice(0, 阅读全文
posted @ 2022-03-28 20:51 GameCat 阅读(590) 评论(0) 推荐(0) 编辑
摘要: let str = " zifu chuan " function func(str, target) { let arr = str.split('') arr.map(function(item, index){ if(item target){ arr.splice(index, 1) } } 阅读全文
posted @ 2022-03-28 20:20 GameCat 阅读(477) 评论(0) 推荐(0) 编辑
摘要: 最简单而且最好理解的一种方法 let str = " zifu chuan " let newStr = str.split(' ').join('') console.log(newStr)// zifuchuan 不管原来的字符串中多少个空格都可以实现 阅读全文
posted @ 2022-03-28 20:05 GameCat 阅读(186) 评论(0) 推荐(0) 编辑

导航