JSFiddle - React, Tailwind, and code Playground

by Adrien Antoine

HTML

<script src="http://underscorejs.org/underscore.js"></script>
<div id="result"></div>
<div id="resultWithoutUnderscore"></div>

JavaScript

var array = ['2', '11', '15', '22', 'Another', 'Test', '1', '10', '19', 'bar', 'baz', 'bob'];

array.sort(function(a, b) {
    
    if (a.match(/^[0-9]+$/)) {
        
        if (b.match(/^[0-9]+$/)) {
            return a - b;
        } else {
            return -1;
        }
        
    } else if (b.match(/^[0-9]+$/)) {
        return 1;
    }
    
    return a.toUpperCase() > b.toUpperCase();
    
});

$('#result').html(array.join(', '));