Sort planets javaScript example
I have wrote a post on the array sort method before hand, and the general idea I have in mind now is to have at least a one if not more javaScript example posts that help to show why the array sort method is useful. Very basic examples are helpful, but they do not help to get people to really understand the connection between the array sort method, and something that is at least starting to look like some kind of project that is fun, interesting or useful. Sorting an array of objects is something that will come up often in javaScript so I thought I would make a fun little javaScript project that would be an example of why sorting is helpful.
This javaScript example will not be a full game, but it will be one little mechanic that could be used in a full game that will of course make use of array sort. Say you have an array of objects, and each object is a planet in some kind of game that has to do with taking over planets. Anyway there would be a lot of code that would need to be written to make a fun little planet attack game, but one feature that I would want is to have a method where I can give a position, and get a list of planets where the first planet in the list is the one that is the closest to that position. This javaScript example will then just be this one little aspect of game development using javaScript, I will also put together some additional code that will be a very basic canvas display.