Thursday, November 25, 2010

Sorting through the holidays

Just wanted to make a quick blog post before I go gorge myself for Thanksgiving. The sort Function is nothing you haven't seen before but important enough that I at least wanted to touch on it. It basially takes an array and goes over the contents and then passes them to your function in pairs. In the event that your function returns 1, the sort function will swap the items and place the second one first. If your function returns -1, then the first item will be first. In the event the function returns 0, sort will not do anything to the items passed from the array.

A word of caution. It is usually best to convert the values to lowercase so that all sorts are case insensitive. This can make your code cleaner and less prone to bugs.

No comments:

Post a Comment