I’ve created an algorithm for the ‘Algorithms: Find the Symmetric Difference’ challenge. From what I can tell, this should be returning the correct answer for at LEAST the first test input. However, it’s claiming the returned output is incorrect. Anyone able to help me unpack the reason why?
My code:
function sym(args) {
args = arguments;
sym = [];
for (var a = 0; a < args.length; a++) {
for (var index of args[a]) {
sym.push(index);
}
}
var temp = 0;
for (var b = 0; b < sym.length; b++) {
for (var c = 0; c < sym.length; c++) {
if (sym[c] > sym[c+1]) {
temp = sym[c+1];
sym[c+1] = sym[c];
sym[c] = temp;
}
}
}
for (var d = 1; d < sym.length; d++) {
if (sym[d-1] == sym[d]) {
delete sym[d-1];
delete sym[d];
}
}
var arr = [];
for (var element of sym){
if (!isNaN(element))
arr.push(element);
}
args = arr;
return args;
}
sym([1, 2, 3], [5, 2, 1, 4]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54.
Challenge: Find the Symmetric Difference
Link to the challenge: