MYYA
consta=[1,2,3,4];constb=[2,3,5,6];functionfilterArr(arr1,arr2,type){letdiffArr=[];letsameArr=[];sameArr=arr1.filter(v=>{returnarr2.some(a=>{returnv==a})})letmergeArr=[...arr1,...arr2];diffArr=mergeArr.filter(v=>{return!sameArr.includes(v)})if(type=='same'){returnsameArr}else{returndiffArr}}console.log(filterArr(a,b,'same'))//[2,3]console.log(filterArr(a,b,'diff'))//[1,4,5,6]