getNearest() result can't be used with indexOf()?

Seems like a bug to me. On greed:

var items = this.getItems();
var peons = this.getByType(‘peon’);

if(peons[0]) {
var item = peons[0].getNearest(items);
var index = items.indexOf(item);

indexOf() will return -1.

(edit to produce working code that shows the bug via say(index))

You have a mistake on the variable definition:

var peons = this.getByType(‘peon’);


You define “peons”, but you are calling “peon”

I hope that helps,

Fair criticism of the above code, which I threw together to explain the problem. Unfortunately that doesn’t change the actual bug. :slight_smile:

(if you use the above code referencing the peons variable correctly, you will hit the bug. If you reference the peon variable incorrectly, you actually just hit an error because peon is undefined)

Also, it shouldn’t actually matter, because if peon were any variable that correctly dereferenced ‘getNearest()’, then it should also return an item that can be found in the items array…

I’ve reproduced the bug. Tracking it over here. I think it is something to do with the API protection turning the object into not-quite-the-same object. Thanks for the bug report.

Awesome. And good to know about _.indexOf as a workaround. :smiley: