ChrisCa
ChrisCa

Reputation: 11006

underscore some method giving unexpected result

I am trying to replace the following bit of code with a call to _.some in the underscore library

var anyInTopRow = false;

            for (var g = 0; g < this.grid[1].length; g++ ) {
                if (this.grid[1][g] != undefined) {
                    anyInTopRow = true;
                    break;
                }
            }

underscore's some/any method:

var anyInTopRow = _.some(this.grid[1], function(x) {x != undefined;});

but they return different results with the same data

what am I doing wrong?

Upvotes: 0

Views: 254

Answers (1)

Prinzhorn
Prinzhorn

Reputation: 22508

You're not returning anything. Try

var anyInTopRow = _.some(this.grid[1], function(x) {return x != undefined;});

Upvotes: 2

Related Questions