If I have an array like:
["23", "765", "sfasf", "2.3E-3", "2.3cE-3"]
How can I order it so numbers(decimals, floats or scientific notation) are ordered ascending and after those strings that aren't numbers(for example "sfasf" or "2.3cE-3")?
Expected order of the example array:
["2.3E-3", "23", "765", "2.3cE-3", "sfasf"]
The order of the strings that can't be converted to numbers doesn't matter, they just must be at the end.
Solution from answer:
$scope.cleanAndOrder = function(dbo, fieldName) {
var textareaId = "textarea"+"_"+fieldName ;
var textarea= document.getElementById(textareaId);
//(+b && (+a!=a)) : return true (converted to 1) if b is a number and a isn't
//(a-b) : then compare the numbers if the first comparaison isn't enough
textarea.value = dbo.attributes[fieldName].sort(function(a,b){ return (+b && !+a) || (a-b) }).join("\n");
var lines = textarea.value.split("\n");
textarea.setAttribute('rows', lines.length +2);
}