JS Array Classificação
numArray.sort((a, b) => a - b); // For ascending sort
numArray.sort((a, b) => b - a); // For descending sort
Worried Wildebeest
numArray.sort((a, b) => a - b); // For ascending sort
numArray.sort((a, b) => b - a); // For descending sort
function eq(x, y) {
if (x < y) return -1;
else if (x > y) return 1;
else return 0;
}
let num = new Array(8, 50, 2, 34, 12, 8);
num.sort(eq);
let text = num.join();
document.write(text);
// Functionless
sort()
// Arrow function
sort((firstEl, secondEl) => { ... } )
// Compare function
sort(compareFn)
// Inline compare function
sort(function compareFn(firstEl, secondEl) { ... })