Hi guys, can anyone help me figure out why this is returning an infinite loop? This is for the symmetric difference algorithm challenge. I just don’t understand what’s going on
function sym(args) {
var arr2 = [];
var hold = 0;
//split out argument into seperate arrays
args = Array.prototype.slice.call(arguments);
//reduce over loops that get symmetric difference between 2 arrays
args.reduce(function(prev, curr) {
//loop over array 1
for (let i = 0; i<prev.length; i++) {
//loop over array 2
for (let j = 0; j<curr.length; j++) {
//if array 1 item matches anything in array 2 then add value to hold (count tracker)
if (prev[i] === curr[j]) {
hold++;
}
}
//if hold is 0 then theres no matches so can be added
if(hold === 0) {
arr2.push(prev[i]);
}
hold = 0;
}
//now do same as above but checking array 2 against array 1
for (let i = 0; i<curr.length; i++) {
for (let j = 0; j<prev.length; j++) {
if (curr[i] === prev[j]) {
hold++;
}
}
if(hold === 0) {
arr2.push(curr[i]);
}
hold = 0;
}
return arr2;
});
return arr2;
}
sym([1, 2, 5], [2, 3, 5], [3, 4, 5]);