I'm trying to write an algorithm that sorts this table by an average value from the each column grouped by the first column(name) so the table display only a rows with the most common values.For example this is the current table:
and after sorting should look like this:
So this is the array I'm trying to sort and show only the most common table values:
var testArray = [
{
"testName": "10b1",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": "NORM",
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": "NEG"
},
{
"testName": "10b1",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": "NORM",
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": "NEG"
},
{
"testName": "10b1",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": "NORM",
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": "NEG"
},
{
"testName": "10b1",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": "NORM",
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": "NEG"
},
{
"testName": "10b1",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": "NORM",
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": "NEG"
},
{
"testName": "10b1.5",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": 50,
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": 50
},
{
"testName": "10b1.5",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": 50,
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": 50
},
{
"testName": "10b1.5",
"SG": 1.010,
"pH":6,
"LEU": "NEG",
"NIT": "NEG",
"PRO": "NEG",
"GLU": 50,
"KET": "NEG",
"UBG": "NORM",
"BIL": "NEG",
"Hb": 50
}
];
I tried to use this algorithm but the result that returns me is far from the expected result:
var mf = 1;
var m = 0;
var item;
var count = 1;
for(let k = 0; k < testArray.length; k++){
for(let v = 0; v < testArray[k].values.length; v++){
current = 1;
for(j = v; j <= testArray[k].values.length; j++){
if(testArray[k].values[v] == testArray[k].values[j]){
m++;
}
if(mf < m){
mf=m;
item = testArray[k].values[v];
testArray[k].values = [];
}
}
testArray[k].values[v] = item;
}
}
I would be grateful if someone can give some sample algorithm or solution to the problem :)