JSFiddle - React, Tailwind, and code Playground

by jasonwilczak

HTML

<div id="output"></div>

JavaScript

/*
This approach is effectively the same as in treecache.js, but instead of storing the full data record at
each node, just stores the IDs for each of the records. This will result in less memory being used, but more processing
will be required to look up the record for each ID
*/

let cache = null;
let idRef = null;


/*
Define the fields as well as how their (normalized) values can be extracted from the record. Values are
normalized for the purposes of comparisons. For job and company, this just means converting their values to lower case.
For name, it is assumed that only the last name is checked, all name field values comprise of a first and
last name separated with a space.
 */
const company = {
    field: "company",
    extractNormalizedValue: function(pRecord) {
        if (!isEmpty(pRecord)) {
            return this.normalizedValue(this.normalizedValue(pRecord.company));
        } else {
            return null;
        }
    },
    normalizedValue: function(pValue) {
        return normalizeValue(pValue);
    }
};

const job = {
    field: "job",
    extractNormalizedValue: function(pRecord) {
        if (!isEmpty(pRecord)) {
            return this.normalizedValue(this.normalizedValue(pRecord.job));
        } else {
            return null;
        }
    },
    normalizedValue: function(pValue) {
        return normalizeValue(pValue);
    }
};

const name = {
    field: "lastname",
    extractNormalizedValue: function(pRecord) {
        if (!isEmpty(pRecord)) {
            return this.normalizedValue(pRecord.name)
        }  else {
            return null;
        }
    },
    normalizedValue: function(pValue) {
        if (!isEmpty(pValue)) {
            let parts = pValue.split(" ");
            if (parts.length > 0) {
                return normalizeValue(parts[parts.length - 1]);
            }
        }
        return pValue;
    }
};

/*
The following indexes will result in the building of a cache that will handle all combinations of...