Symmetric Difference: tests failing

Symmetric Difference: tests failing
0

#1

Tell us what’s happening:
I’ve solved this challenge and input it into the fcc interface. The results displayed (console.log) match those outlined on the challenge page, but every single test reports failure when I check them.
I’ve been working in PythonTutor to see it run live and I get the desired results there as well.
Any idea why this isn’t passing?

Your code so far

  // convert object to array
  args = Array.prototype.slice.call(arguments);

// check that item in position doesn't = item in position immediately before it, returns only unique values
 function single(a) {
  return a.sort().filter(function(el, pos, ary) {
   return !pos || el != ary[pos-1];
  }); 
 }
 
 function duplicates(b) {
  b.forEach(function(el) {
   return b.filter(function(el, pos, ary) {
      var firstPos = b.indexOf(el);
      // remove both item & value in position that matched
      if (firstPos !== pos) {
        b.splice(firstPos, 1);
        b.splice(pos-1, 1); 
      }
    });
  }); 
 }
 var arr1 = arguments[0];
  for (var a = 1; a < args.length; a++) {
    arr1 = single(arr1);
    var arr2 = arguments[a];
    arr2 = single(arr2);
    var merged = arr1.concat(arr2);
    duplicates(merged);
    arr1 = merged;
  }
      

 var sorted = arr1.sort();
  console.log(sorted);
  return sorted;
}

sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3], [5, 3, 9, 8], [1]);

Your browser information:

Your Browser User Agent is: Chrome Version 63.0.3239.84 (Official Build) (64-bit).

Link to the challenge:


#2

You can see the console.log's output on the browser console. I have no idea why the output on the challenge page outputs the expected value, but the values on the console are quite different.


#3

When I add:

function sym() {

above what you have posted above, I can pass all the tests on the FCC site.


#4

Removing the args from the parameter list solves the challenge? Interesting…


#5

I think I’ve figured it out. You have stored arguments as a proper array in the args variable, but you still directly referenced arguments later in the code twice. Since args now holds all of the arguments in one array, arguments[0] actually refers to all of them (arguments[0] == args since args is the first parameter in the parameter list), not just the first arg. Changing arguments to args should fix the bug.


#6

This worked. Thank you!