Here is the problem with sort. Lets say I have an array of strings like this:
let things = [‘Building’, ‘Car’, ‘house’, ‘tree’, ‘bicycle’, ‘automobile’];
It will not sort correctly if I use:
The reason is that I have a mixture of upper and lowercase characters. The uppercase characters will sort first and we end up with this.
‘Building’, ‘Car’, ‘automobile’, ‘bicycle’, ‘house’, ‘tree’
The solution is pretty simple; we just need to sort with the correct case. However, executing on that solution is not quite as simple. There are a number of different ways to do this. In the tutorial I chose to take advantage of a little known feature of sort; you can pass in a function to the sort method that can be used to determine the sort order. That makes sort a higher order function, and that was the reason I was using it as an example in the tutorial.
The end result is kind of cool.
If you would like to understand higher order function better or you are interested in the sort solution, take a look at this tutorial.