2022年3月29日

摘要: function toLeft([first, ...rest]) { return [...rest, first]; } function toRight(arr) { return [arr.pop(), ...arr]; } const arr = [1, 2, 3, 4, 5]; cons 阅读全文
posted @ 2022-03-29 11:22 GameCat 阅读(607) 评论(0) 推荐(0) 编辑
摘要: let arr = [3, 4, 5, 2, 1]; let sum = arr.reduce((pre, next) => { pre += next; return pre; }, 0) console.log('结果:', sum); 阅读全文
posted @ 2022-03-29 11:10 GameCat 阅读(205) 评论(0) 推荐(0) 编辑
摘要: const isPureArray = array => { return [...new Set(array)].length array.length } console.info(isPureArray([1, 2, 3, 4])) // true console.info(isPureArr 阅读全文
posted @ 2022-03-29 10:56 GameCat 阅读(42) 评论(0) 推荐(0) 编辑
摘要: let res = 'aabbaaaaccdeee'.replace(/(.)\1*/g, '$1'); console.log(res)// abacde 阅读全文
posted @ 2022-03-29 10:02 GameCat 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 方法1 let obj1 = {} let obj2 = {a:1} function func(obj) { for(let key in obj) return false return true } console.log(func(obj1)) console.log(func(obj2)) 阅读全文
posted @ 2022-03-29 09:57 GameCat 阅读(32) 评论(0) 推荐(0) 编辑
摘要: const number = test || 0; 当test值为truthy时,取test的值,否则取0。这样可以避免number被赋为NaN、null、undefined、false等值。 const number = test && test.value; 当test值为truthy时,再去取 阅读全文
posted @ 2022-03-29 09:40 GameCat 阅读(36) 评论(0) 推荐(0) 编辑
摘要: const arr1 = [1,2,3, 3, 2] const getUniqueArray = arr => [...new Set( arr)]; let res = getUniqueArray(arr1) console.log(res) 阅读全文
posted @ 2022-03-29 09:31 GameCat 阅读(576) 评论(0) 推荐(0) 编辑
摘要: (function () { console.log('自执行函数1'); })(); (function () { console.log('自执行函数2'); }()); !function () { console.log('自执行函数3'); }(); + function () { con 阅读全文
posted @ 2022-03-29 09:26 GameCat 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 方法1 let arr1 = [1,2,3] let arr2 = arr1 arr1 = [] console.log(arr1,arr2) // [] [1,2,3] 方法2 const arr1 = [1,2,3] const arr2 = arr1 arr1.length = 0 conso 阅读全文
posted @ 2022-03-29 09:19 GameCat 阅读(42) 评论(0) 推荐(0) 编辑

导航