Baseline Widely available
O método sort()
ordena os elementos de uma matriz tipada no local e retorna a matriz ordenada. Esse método tem o mesmo algoritmo que Array.prototype.sort()
. TypedArray é uma das maneiras de escrever matrizes.
typedarray.sort([compareFunction])Parâmetros
compareFunction
Optional
Especifica uma função que define a ordem de classificação.
A matriz ordenada.
ExemplosPara mais exemplos, acesse o método Array.prototype.sort()
.
var numbers = new Uint8Array([40, 1, 5, 200]);
numbers.sort();
// Uint8Array [ 1, 5, 40, 200 ]
// A compare function is not required as in the case of Array
// to sort the numbers numerically.
var numbers = [40, 1, 5, 200];
numbers.sort();
// The elements are sorted as strings.
// [1, 200, 40, 5]
function compareNumbers(a, b) {
return a - b;
}
numbers.sort(compareNumbers);
// [ 1, 5, 40, 200 ]
Especificações Compatibilidade com navegadores Ver também
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4