JSFiddle - React, Tailwind, and code Playground

by JonNorman

JavaScript

var orderedQualityParameters = ["APPEARANCE","ASSAY","PURITY","SPECIFIC OPTICAL ROTATION","LOSS ON DRYING","MELTING POINT","IDENTITY","RESIDUE ON IGNITION","SOLUBILITY","ELEMENTAL ANALYSIS","HEAVY METALS"];
theArray=[{QualityParameter:"Dpperaance"},{QualityParameter:"Elemental Analysis",indexWas:1},{QualityParameter:"Appearance"},{QualityParameter:"Cppearance"}];
theArray.sort(function(a,b){
  qpa = a.QualityParameter;
  qpb = b.QualityParameter;
  //SpecificOrder
  ioa = orderedQualityParameters.indexOf(qpa.toUpperCase());
  iob = orderedQualityParameters.indexOf(qpb.toUpperCase());
  if (ioa>-1 && iob>-1){
    return (ioa-iob);
  }else if (ioa>-1){
    return -1;
  }else if (iob>-1){
    return 1;
  }
  //Alphabetical Order
  return qpa>qpb?1:qpb>qpa?-1:0
});
for (var i=0;i<theArray.length;i++){
	alert (theArray[i].QualityParameter);
}