Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected identifier error in javascript

Tags:

javascript

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.

like image 468
Suavocado Avatar asked Apr 26 '26 13:04

Suavocado


1 Answers

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; 
}  
like image 94
void Avatar answered Apr 29 '26 02:04

void



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!