let arr = [1,2,3,7,8,9,10]
function setArr(item){
let s1 = new Set([...arr,...item]);
let arr2 = [];
for(let a of s1){
arr2.push(a);
}
return arr2.filter(e=>item.includes(e))
}
console.log(setArr([1,3,4,5]))
console.log(setArr([1,2,3,4,11]))
let arr1 = [1,2,3,7,8,9,10]
function setArr1(item){
let newArr = []
for(let i=0;i<item.length;i++){
let isa = true
for(let j=0;j<arr1.length;j++){
if(item[i]==arr1[j]){
newArr.push(arr1[j])
isa = false
}
}
if(isa) newArr.push(item[i])
}
return newArr
}
console.log(setArr1([1,3,4,5]))
console.log(setArr1([1,2,3,4,11]))
console