Skip to content

Instantly share code, notes, and snippets.

@angle943
Created February 3, 2020 05:08
Show Gist options
  • Save angle943/2f4433a30f7c022d8ade583e73d3e82f to your computer and use it in GitHub Desktop.
Save angle943/2f4433a30f7c022d8ade583e73d3e82f to your computer and use it in GitHub Desktop.
Javascript Freecodecamp Algorithm #27: Find The Symmetric Difference (N Cubed Solution)
const symOfTwo = (arr1, arr2) => {
const output = [];
for (const el of arr1) {
if (!output.includes(el) && !arr2.includes(el)) {
output.push(el);
}
}
for (const el of arr2) {
if (!output.includes(el) && !arr1.includes(el)) {
output.push(el);
}
}
return output;
};
function sym() {
const arrOfArrs = [...arguments];
let output = arrOfArrs[0];
for (let i=1; i < arrOfArrs.length; i++) {
output = symOfTwo(output, arrOfArrs[i]);
}
return output.sort((a, b) => a - b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment