Skip to content

Instantly share code, notes, and snippets.

@heanfig
Created November 2, 2020 23:55
Show Gist options
  • Save heanfig/7345059d1b8cf303773dbe75c4ebb185 to your computer and use it in GitHub Desktop.
Save heanfig/7345059d1b8cf303773dbe75c4ebb185 to your computer and use it in GitHub Desktop.
function sym(...args) {
return args.reduce( (a,b,i) => {
const valoresA = a.filter(item => !b.find(aux=>aux===item));
const valoresB = b.filter(item => !a.find(aux=>aux===item));
const resultado = new Set([...valoresA, ...valoresB]);
return [...resultado].sort((a,b)=>a-b)
},[]);
}
console.log(sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6])); //[1, 4, 6, 7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment