I'm trying to sort array with custom values, by it's integer value. There is my array:
[ 'a>46', 'a>86', 'h>78' ]
And desired output:
[ 'a>46', 'h>78', 'a>86' ]
Note: the largest possible value to be found in my array is 90.
I'm trying this way:
var newarr = [];
var max = 91;
for (let u = 0; u < array.length; u++) {
var nmbr = parseInt(array[u].replace(/\D/g,'')); // get integer of array element
if (nmbr < max) { // if element is lower than current highest value
max = nmbr;
newarr[0] = array[u]; // assign it to the beggining of new array
} else { // else put it at as the next newarr element
newarr[newarr.lenght+1] = array[u];
}
}
Output:
[ 'a>46', <1 empty item>, 'a>86' ]
minutsycan you add a snippet?