摘要: function square(arr) { //为数组 arr 中的每个元素求二次方。不要直接修改数组 arr,结果返回新的数组 return arr.map(x=>x*x); } 阅读全文
posted @ 2020-11-02 21:48 WP-WangPin 阅读(159) 评论(0) 推荐(0) 编辑
摘要: function remove(arr, item) { //返回arr中和item不相同的值 return arr.filter(x=>x!==item); } 阅读全文
posted @ 2020-11-02 21:01 WP-WangPin 阅读(2071) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2020-11-02 20:39 WP-WangPin 阅读(154) 评论(0) 推荐(0) 编辑
摘要: function sum(arr) { let count=0; arr.forEach(function(x){ count+=x; }) return count; } function sum(arr) { return arr.reduce((a,b)=>a+b,0); } 阅读全文
posted @ 2020-11-02 13:01 WP-WangPin 阅读(246) 评论(0) 推荐(0) 编辑