Sort an array using javascript
//Sort an array of numbers in assending order using javascript
function assendOrder(arr){
return arr.sort( (a, b) => a - b);
}
//Sort an array alphabetically in reverse order javascript
function reverseAlpha(arr){
return arr.sort((a, b)=> a === b ? 0 : a < b ? 1 : -1 );
}
console.log(reverseAlpha(['l', 'h', 'z', 'b', 's']));
//[ 'z', 's', 'l', 'h', 'b' ]
//Sort an array alphabetically order javascript
function alphabeticalOrder(arr){
return arr.sort((b, a)=> a === b ? 0 : a < b ? 1 : -1 );
}
console.log(alphabeticalOrder(["a", "d", "c", "a", "z", "g"]));
//[ 'a', 'a', 'c', 'd', 'g', 'z' ]