How to do this challenge?

Tell us what’s happening:

  **Your code so far**

function sym(args) {
return args;
}
[3, 4, 5]

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/88.0.4324.190 Safari/537.36.

Challenge: Find the Symmetric Difference

Link to the challenge:

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

2 Likes

You should not be providing solutions in direct response to a camper’s question. We’ve discovered that it is much more effective to guide someone to reaching their own solution by answering questions, instead of providing the solution for them.

@clausewinklestein One thing that can be confusing about this challenge is that the arguments they have provided in its original form will not work, and there are two ways to get around this, you can either use the arguments object (more on that here: The arguments object - JavaScript | MDN), or you can use the rest parameters to turn args into an array that holds all the arguments, and this is the method I recommend (more on it here: Rest parameters - JavaScript | MDN)

1 Like

I’m going to write a bit of pseudo code to help with understanding the problem:

//I have 3 arrays
let a = [1];
let b = [2];
let c = [1];
//I want to compare them such that I'm only comparing two at a
//time, and to do this we will start with the first two arrays.
//We will join the two arrays together such that only their
//differences comprise the new array
function compare(array1, array2) {
    let a  = [];
    
    for (let i = 0; i < lengthOfTheLongestArray; i++) {
        if (longestArray[i] isNotIn shorterArray) {
            a.push(longestArray[i])
        }
    }
    return a;
}

let d = compare(a, b);
console.log(d) //[1,2]
d = compare(c, d);
console.log(d) //[1, 2]

The code I’ve written above is not the answer, and may not exactly work if extrapolated into real code, but I hope it gives you some ideas.

2 Likes
function sym(args1, args2){
            for(let i=0; i<args1.length; i++){
                for(let j=0; j<args2.length; j++){
                    if(args1[i]===args2[j]){
                        args1.splice(i,1);
                        args2.splice(j,1);
                        i--;
                        j--;
                    }
                }            
            }
            let args=args1.concat(args2);
            
            return args; 
        }
        sym([1, 2, 3], [5, 2, 1, 4]);
1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

1 Like

Thanks for feedback. Noted for future.