array sort reverse javascript code example
Example 1: reversing an array in js
var arr=[1,2,5,6,2]
arr.reverse()
Example 2: javascript sort descending
function sortEggsInNest(a, b) {
return a > b ? -1 : b > a ? 1 : 0;
}
var arr=[1,2,5,6,2]
arr.reverse()
function sortEggsInNest(a, b) {
return a > b ? -1 : b > a ? 1 : 0;
}