JSFiddle - React, Tailwind, and code Playground
JavaScript
/*
Arr Sort for Browser List
Am checking for ints here, if they are floats than you need to change
the regex accordingly.
*/
var normalTest = ['53 beta', '52 dev', '51', '50', '49', '48', '47', '46'];
var auroraTest = ['53 aurora', '52 beta', '51', '50', '49', '48', '47', '46'];
var randomTest = ['53 beta', '52', '51', '50', '49', '48', '47', '46'];
function browserSort(arr) {
var intPos;
for(var i = 0, l = arr.length; i < l; i++) {
//Get the first string arr item with only integer
if(/^\d+$/.test(arr[i])) {
arr[i] = arr[i] + ' latest'; // rename the first int pos to latest
intPos = i;
break;
}
}
intPos++; // +1 for offset before slice
//Get browsers which are in beta, dev, aurora
var specialBrowsers = arr.slice(0, intPos).reverse();
//Get rest of the browsers
var otherBrowsers = arr.slice(intPos);
//Concat both arrays
return specialBrowsers.concat(otherBrowsers);
}
console.log(browserSort(normalTest));
console.log(browserSort(auroraTest));
console.log(browserSort(randomTest));