(Javascript) Will findNearest sort objects into an array?


#1

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?


#2

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).


#3

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:


#4

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.


#5

Nope. sorting works just fine.