Number sorting in javascript array

<button onclick="AscendingSorting()">Ascending</button>
<button onclick="DescendingSorting()">Descending</button>
<p id="demo"></p>

<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = points;

function AscendingSorting() {
points.sort(function(a, b){return a>b});
document.getElementById("demo").innerHTML = points;
}

function DescendingSorting() {
points.sort(function(a, b){return b>a});
document.getElementById("demo").innerHTML = points;
}
</script>

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *