Tech_Dev

Tech_Dev

Share

this page is going to be about web technologies where people can share technology and also learn web technologies.

23/05/2023

Symmetry difference Algorithm

function sym() {
const args = [];

for (let i=0; i< arguments.length; i+=1) {
args.push(arguments[i]);
}

return args.reduce((acc, curArr) => {
let ac = [...acc];
const result = [];
for (let i=0; i< ac.length; i+=1) {
if(curArr.indexOf(ac[i])== -1 && result.indexOf(ac[i]) == -1){
result.push(ac[i]);
}
}
for (let i=0; i< curArr.length; i+=1) {
if(ac.indexOf(curArr[i]) == -1 && result.indexOf(curArr[i])==-1) {
result.push(curArr[i]);
}
}
return [...result];
});
}

console.log(sym([1, 2, 3], [5, 2, 1, 4]));

Output: [ 3, 5, 4 ];

Want your business to be the top-listed Advertising & Marketing Company in Gurugram?
Click here to claim your Sponsored Listing.

Category

Telephone

Address


Gurugram
Gurugram
122505