Skip to content

Instantly share code, notes, and snippets.

@lostvikx
Created December 22, 2021 19:54
Show Gist options
  • Save lostvikx/6be8aa41657fd29193eb5fc8c3ea1b06 to your computer and use it in GitHub Desktop.
Save lostvikx/6be8aa41657fd29193eb5fc8c3ea1b06 to your computer and use it in GitHub Desktop.
function sym(...args) {
function filterRepeat(arr) {
const filteredList = [];
for (const n of arr) {
if (!filteredList.includes(n)) {
filteredList.push(n);
}
}
return filteredList;
}
while (args.length > 1) {
const arr1 = filterRepeat(args[0]);
const arr2 = filterRepeat(args[1]);
const combined = arr1.concat(arr2);
const freqObj = {};
for (const n of combined) {
const key = String(n);
if (freqObj[key] === undefined) {
freqObj[key] = 1;
} else {
freqObj[key]++;
}
}
const result = [];
for (const key in freqObj) {
if (freqObj[key] == 1) {
result.push(Number(key));
}
}
args.splice(0, 2, result);
}
return args[0];
}
console.log(sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])); // [1, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment