Move this code to a named function that you can pass to the sort() method.