back to Overview

.sort()

Sorts the list elements and returns a new, sorted list.
Util module only.

Syntax Variants

list.sort()
list.sort(cmpFunc)

Parameters

cmpFunc (optional)
an optional function(a, b) to compare two list elements. It must return a number <0 if a is smaller, than b >0 if b is larger and 0 if both are equal. If the function is omitted, the list elements will be converted into strings and compared lexicographically.
(return value)
a new, sorted list

Description

Sorts the list elements and returns a new, sorted list. You can specify a function to compare two elements. If you don't, the list elements will be converted into strings and sorted lexicographically.

sort() uses Array's method of the same name internally and shares its properties.

Example

Sort a few names:

var sorted = _('Harry', 'Bert', 'Tom', 'Bo').sort(); // returns _('Bo', 'Bert', 'Harry', 'Tom')

Comments

comments powered by Disqus

back to Overview

Functions