Collection.prototype.sort()

Sort the files in the collection.

Syntax

collection.sort(compare function(a, b File) int) Collection

Parameters

compare function(a, b File) int

A callback function to decide if a or b shall come first in the resulting collection.

compare shall return:

  • a negative number to sort a before b,
  • 0 to preserve the relative order of a and b,
  • a positive number to sort b before a.

Description

Return a new sorted collection. The order of files is determined by a user defined compare function. The sort is stable, that is, the original order of equal elements is preserved.

See also .sortBy() which is simpler and faster.

Examples

Sort files in the collection by name.