Created
February 3, 2020 05:08
-
-
Save angle943/2f4433a30f7c022d8ade583e73d3e82f to your computer and use it in GitHub Desktop.
Javascript Freecodecamp Algorithm #27: Find The Symmetric Difference (N Cubed Solution)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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