摘要:
function toLeft([first, ...rest]) { return [...rest, first]; } function toRight(arr) { return [arr.pop(), ...arr]; } const arr = [1, 2, 3, 4, 5]; cons 阅读全文
摘要:
let arr = [3, 4, 5, 2, 1]; let sum = arr.reduce((pre, next) => { pre += next; return pre; }, 0) console.log('结果:', sum); 阅读全文
摘要:
const isPureArray = array => { return [...new Set(array)].length array.length } console.info(isPureArray([1, 2, 3, 4])) // true console.info(isPureArr 阅读全文
摘要:
let res = 'aabbaaaaccdeee'.replace(/(.)\1*/g, '$1'); console.log(res)// abacde 阅读全文
摘要:
方法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)) 阅读全文
摘要:
const number = test || 0; 当test值为truthy时,取test的值,否则取0。这样可以避免number被赋为NaN、null、undefined、false等值。 const number = test && test.value; 当test值为truthy时,再去取 阅读全文
摘要:
const arr1 = [1,2,3, 3, 2] const getUniqueArray = arr => [...new Set( arr)]; let res = getUniqueArray(arr1) console.log(res) 阅读全文
摘要:
(function () { console.log('自执行函数1'); })(); (function () { console.log('自执行函数2'); }()); !function () { console.log('自执行函数3'); }(); + function () { con 阅读全文
摘要:
方法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 阅读全文