[go: up one dir, main page]

0% found this document useful (0 votes)
31 views1 page

Find The Symmetric Difference

The function sym takes any number of arguments which are arrays and returns a new array containing only the unique items among all the input arrays by filtering out items that are included in other arrays using a diff function.

Uploaded by

JuanCarlosGuaña
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Find The Symmetric Difference

The function sym takes any number of arguments which are arrays and returns a new array containing only the unique items among all the input arrays by filtering out items that are included in other arrays using a diff function.

Uploaded by

JuanCarlosGuaña
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

function sym(...

args) {

const diff = (result, current) => {


const arr1 = result.filter(item=>!current.includes(item))
const arr2 = current.filter(item=>!result.includes(item))
return [...arr1,...arr2]
}

return [... new Set(args.reduce(diff))]

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

You might also like