JSFiddle - React, Tailwind, and code Playground

by Kai

JavaScript

var json = JSON.parse('{"myservices": [{"name": "oozie", "hostidn": "1", "details": "failed process health monitor....", "currstatus": "Warning", "currstatusclass": "warning"}, {"name": "oozie", "hostidn": "2", "details": "failed process health monitor....", "currstatus": "Warning", "currstatusclass": "warning"}, {"name": "oozie", "hostidn": "3", "details": "failed process health monitor....", "currstatus": "Warning", "currstatusclass": "warning"}, {"name": "oozie", "hostidn": "4", "details": "failed process health monitor....", "currstatus": "Warning", "currstatusclass": "warning"}, {"name": "oozie", "hostidn": "5", "details": "failed process health monitor....", "currstatus": "Warning", "currstatusclass": "warning"}, {"name": "single-namenode", "hostidn": "2", "details": "failed process health monitor....", "currstatus": "Warning", "currstatusclass": "warning"} ] }');

function getHighHostIdn (json) {
    var i = 0;
        hostidns = [],
        len = json.myservices.length,
        highest = null,
        matches = [];
    
    for (; i < len; i++) {
        hostidns.push(parseInt(json.myservices[i].hostidn, 10));
    }
    
    highest = Math.max.apply(null, hostidns);
    
    for (i = 0, len = hostidns.length; i < len; i++) {
        if (hostidns[i] === highest) {
            matches.push(json.myservices[i]);
        }
    }
    
    return matches;
}

console.log(getHighHostIdn(json));