// function combine () {
// let arr = [].concat.apply([], arguments)
// return Array.from(new Set(arr))
// }
// let m = [1,2,3,5];
// let n = [2,5,7,8];
// console.log(combine(m,n))
// 数组去重
let arr1 = [1,3,2,34,5,6,7,34,1,8,9,0,0]
const unique = arr1.filter((item,index,res) => {
return res.indexOf(item) === index
})
unique.sort((a,b) => a-b)
console.log(unique)
// 合并数组 求和
let arr=[
{id:1,value:2},
{id:2,value:6},
{id:1,value:4},
{id:2,value:1}]
// 结果 => [{id:1,value:6},{id:2,value:7}]
// console.log(arr.filter(ele => ele.id === 1))
// var combineArr = function(arr= [], query) {
// var valueadd = 0
// let targetArr = arr.filter(ele => ele.id === query)
// return targetArr
// }
// console.log(combineArr(arr,2))
const newArr = [...new Set(arr.map(a => a.id))].map(id => ({
id,
value: arr.filter(a => a.id === id).reduce((a, b) => a + b.value, 0),
}))
console.log(newArr)
// 筛选
const fruits = ['apple', 'banana', 'grapes', 'mango', 'orange','中国','美国'];
const filterItems = (query) => {
return fruits.filter((el) =>
el.toUpperCase().indexOf(query.toUpperCase()) > -1
);
}
console.log(filterItems('ap')); // ['apple', 'grapes']
console.log(filterItems('an')); // ['banana', 'mango', 'orange']
console.log(filterItems('国'))
console