So this little snippet of code takes an array A
of integers and makes the integers strings when they become the keys of pairs
. Why? Python is happy for them to remain integers, but JavaScript seems to only want strings for keys.
var pairs = {};
for(var i=0; i < A.length; ++i) {
var value = A[i];
if(pairs[value]) {
delete pairs[value];
} else {
pairs[value] = true;
}
}
console.log(A, pairs)
Produces:
Example test: [9, 3, 9, 3, 9, 7, 9]
Output:
[ 9, 3, 9, 3, 9, 7, 9 ] { '7': true }
OK
Your test case: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Output:
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] { '10': true }
Returned value: 10
All the keys are integers when they are added to the pairs object, but they become strings when they are used as keys. This is a good bit different from Python.