Sorting Arrays
Sorting Arrays
Arrays
Sorting arrays
Here we have a numbers array.
Until now, we have only dealt with sorted arrays, in real life however, arrays often come
unsorted.
If they are in the right order, it will skip to the next two
elements, otherwise it will rearrange the elements.
Sorting objects
To sort the courses by name, we pass in a function for comparison.
This is because the first condition is true, the return keyword will break out
of the function, so control flow won’t reach the second if statement.
This means there is no need for the else keyword, so we leave it out to make
our code cleaner.
Case Sensitivity
If we change the J in JavaScript to a
lowercase j, we see that Node.js appears
first.