Tell us what’s happening:
Hi,
so I just started working on this challenge and wanted to use the includes() method to check for duplicates as you can see in my code, but I don’t understand why the behavior of includes is different outside vs inside the for loop.
The console.log outside the for loop prints true as it should, but the same console.log for the same index 2 prints false inside the loop.
What am I doing wrong?
Thanks so much in advance and sorry that my english is kinda bad
Your code so far
function sym() {
let result = [];
result = arguments[0];
console.log(result.includes(result[2],2+1));
for (let ind in result){
console.log("ind:"+ind+" result[ind]:"+result[ind]+" "+result.includes(result[ind],ind+1));
}
return result;
}
console.log(JSON.stringify(sym([1, 2, 3, 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/75.0.3770.142 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/algorithms/find-the-symmetric-difference