//数组扁平化后去重并且升序排列
Array.prototype.flat1=function(){
let arr=this
const process_arr= arr.map(function(item){
if(Array.isArray(item)){
return item.flat1()
}else{
return item
}
})
return [].concat(...process_arr)
}
Array.prototype.flat2=function(){
let arr=this
while(arr.some((item)=>Array.isArray(item))){
arr=[].concat(...arr)
}
return arr
}
function combine(arr,...fns){
let res=undefined
for(let i=0;i<fns.length;i++){
res=fns[i].call(arr,res)
}
return res
}
function removeDuplicateArrItem(arr){
return [...new Set(arr)]
}
function WashArr(arr){
return arr.sort((a,b)=>a-b)
}
const arr=[1,2,3,[4,5,[678,[59,[35,61,[87]],1,2,3]]]]
const arr1=[[[[4]],59],6]
const arr3=[[33,44],5,5,5,[[99,99,[100,101]]]]
// console.log(arr.flat1(),arr1.flat1(),"\n")
console.log(arr3.flat1())
console.log(combine(arr3,Array.prototype.flat1,removeDuplicateArrItem,WashArr),"\n")
console.log(arr.flat2())
console.log(combine(arr,Array.prototype.flat2,removeDuplicateArrItem,WashArr))