1 let _ = { 2 chunk(arr, nub) { 3 var res = []; 4 for (var i = 0; i < arr.length; i += nub) { 5 result.push(arr.slice(i, i + nub)) 6 }; 7 console.log(res) 8 return result; 9 }, 10 compact (arr) { 11 let res = []; 12 arr.forEach( item => { 13 typeof item === ‘number‘ && res.push(item) 14 } ); 15 console.log(res) 16 return res 17 } 18 }; 19 20 _.chunk([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], 3) 21 _.compact([0, 1, false, 2, ‘‘, 3, null, ‘1‘]);
原文地址:https://www.cnblogs.com/vant850/p/10474323.html
时间: 2024-12-17 14:12:06