JSFiddle - React, Tailwind, and code Playground

by nevkatz

JavaScript

let arr = [5,3,1,2,3,100];
function sortTest() {



 let sorted = [];

 let shortest = null;

 for (var item of arr) {

    if (!shortest || item < shortest) {
       sorted.unshift(item);
    }
    else {
       sorted.push(item);
    }
 }

  console.log(sorted);
}

function compareNumbers(a, b) {
  return a - b;
}

let sorted = arr.sort(compareNumbers);

console.log(sorted);