JSFiddle - React, Tailwind, and code Playground

HTML

<div id="output"></div>

JavaScript

var arr = [5,9,7,4,2,3,15,8,7,2,undefined,undefined];

function compare(a,b){
    if(a > b){return 1;}
    if(b > a){return -1;}
    return 0;
}

//the short hand function for the sort is this: function (a,b){return a-b}
//but this example makes it a little easier to see what's going on.

arr.sort(compare);

document.getElementById("output").innerHTML = arr;