array sort
/*
sort can be passed a compare function as a callback.
The compare function should return a negative number if a should be before b,
a positive number if a should be after b, or 0 if they are equal.
If no compare (callback) function is passed in,
it will convert the values to strings and sort alphabetically.
sort actually alters the array in place. However, it also returns this sorted array.
*/
// e.g. sort the elements from smallest to largest
var array = [1, 12, 21, 2];
array.sort(function(a, b) {
return a - b;
});
// if a - b is positive, as per rule, a will be placed after b
// if a - b is negative, as per rule, a will be placed before b