reduce函数,reduce函数python

首页 > 教育 > 作者:YD1662024-04-07 21:10:51

9.元素计数

const countOccurrences = (arr) => arr.reduce((acc, curr) => { acc[curr] = (acc[curr] || 0) 1; return acc; }, {}); let arr = [1, 2,3,4,2, 3, 4, 5]; console.log("参数为:", arr); console.log("结果为:", countOccurrences(arr));

reduce函数,reduce函数python(9)

10.并集函数

const union = (...arrays) => arrays.reduce((acc, curr) => [...new Set([...acc, ...curr])], []); let arr = [1, 2,3,4,2, 3, 4, 5]; let arr1 = [1, 2, 3, 4, 5]; console.log("参数为:", arr,arr1); console.log("结果为:", union(arr,arr1));

reduce函数,reduce函数python(10)

11.交集函数

const intersection = (...arrays) => arrays.reduce((acc, curr) => acc.filter(value => curr.includes(value))); let arr = [1, 2,3,4,2, 3, 4, 5]; let arr1 = [1, 2, 3, 4, 5]; console.log("参数为:", arr,arr1); console.log("结果为:", intersection(arr,arr1));

reduce函数,reduce函数python(11)

12.差集函数

const difference = (arr1, arr2) => arr1.reduce((acc, curr) => arr2.includes(curr) ? acc : [...acc, curr], []); let arr = [1, 2,3,4,2, 3, 4, 5,9]; let arr1 = [1, 2, 3, 4, 5,7,8]; console.log("参数为:", arr,arr1); console.log("结果为:", difference(arr,arr1));

reduce函数,reduce函数python(12)

上一页12345下一页

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.