(Javascript) Will findNearest sort objects into an array?


If I implement findNearest like this:

var enemies = this.findNearest(this.findEnemies());

will it populate the array in order of nearest? Or is it just for single objects?


this.findNearest() returns the (one and only) nearest object from the given array. In your example, you would get the nearest enemy. The array is not modified during this process (which in this case is irrelevant anyways).


Thanks. If it sorted the whole array of enemies by distance it would have changed my approach to the trials.
Good to know :slight_smile:


There is (should be) a sort method in JavaScript, you might want to google that. Somehow I think that there was a bug with sorting, but I’m not 100% sure. You might as well just try it and see what happens.


Nope. sorting works just fine.