Collection.prototype.sortBy()

Sort files in the collection by a scalar.

Syntax

collection.sortBy(toScalar function(f File) Number) Collection collection.sortBy(toScalar function(f File) String) Collection

Parameters

toScalar function(f File) Number

A callback function to assign a numeric value to each file for sorting.

toScalar function(f File) String

A callback function to assign a string value to each file for sorting.

Description

Return a new collection sorted by a scalar. The scalar value is defined by a callback function. The sort is stable, that is, the original order of equal elements is preserved.

This method does the same thing as .sort() except .sortBy() is simpler, faster.

Examples

Sort files in the collection by name.

Sort files by body size.

Comparing Integers with Floats should succeed.