What’s happening:
One of the tests has the inputs of: [1, 2, 5], [2, 3, 5], [3, 4, 5]
With the expected output to be: [1, 4, 5]
But that doesn’t seem to make sense because 5 appears in all of the sets. Why is it included as the answer? I thought the solution would be [1,4]
Can anyone explain?
My code so far
function sym(args) {
let sets = Array.from(arguments);
let values = sets.reduce( (a, b) => { return a.concat(b) } );
values.sort( (a,b) => { return a-b })
console.log(values)
let filtered_values = values.filter( (value) => {
let first_index = values.indexOf(value);
if( values.indexOf(value, first_index + 1) === -1 ) { return value }
})
return filtered_values
}
sym([1, 2, 3], [5, 2, 1, 4]);
My browser information:
My Browser User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0
.
Link to the challenge:
https://www.freecodecamp.org/challenges/symmetric-difference