I am getting an unexpected identifier error for the following function.
function merge (one, two) {
one.forEach(function(assign){
//////////this next line is throwing the error////////////
if (two.some(function(req) req.related == assign.rid)) {
if (one.some(function(iter) iter.rid == req.rid)) {
iter.quantity++;
} else {
one.push(req);
}
}
});
return one;
}
The function is intended to operate on an array of objects.
You have missed some { } around .some(function()...
function merge (one, two) {
one.forEach(function(assign){
if (two.some(function(req){ req.related == assign.rid})) {
// ^-- This one you missed
if (one.some(function(iter){ iter.rid == req.rid})) {
// ^-- This one you missed as well
iter.quantity++;
} else {
one.push(req);
}
}
});
return one;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With