JSFiddle - React, Tailwind, and code Playground

by Michael Dibbets

JavaScript

function SimpleMap(keyobj,valueobj) {
    if(typeof keyobj !== 'undefined' && keyobj !== null) {
        if(typeof keyobj === 'function') {
            this.key = keyobj;
        }
        else {
            this.key = keyobj.constructor;
        }
    }
    if(typeof valueobj !== 'undefined' && valueobj !== null) {
        console.log(valueobj);
        if(typeof valueobj === 'function') {
            this.value = valueobj;
        }
        else {
            this.value = valueobj.constructor;
        }
    }
    this.list = {};
}
SimpleMap.prototype.getKeyByValue = function( value ) {
    if(typeof this.value !== 'undefined') {
        if(!(value.constructor === this.value)) {
            throw new Error("Invalid value type. given:"+value);
        }
    }
    for( var prop in this.list ) {
        if( this.list.hasOwnProperty( prop ) ) {
             if( this.list[ prop ] === value )
                 return prop;
        }
    }
    return null;
}
SimpleMap.prototype.size = function() {
   var count = 0;
   for( var prop in this.list ) {
        if( this.list.hasOwnProperty( prop ) ) {
             ++count;
        }
    }
    return count;
}
SimpleMap.prototype.isEmpty = function() {
    return this.size() === 0;
}
SimpleMap.prototype.empty = function() {
   this.list = {};
}
SimpleMap.prototype.put = function(key, value) {
    if(typeof this.value !== 'undefined') {
        if(!(value.constructor === this.value)) {
            throw new Error("Invalid value type. given:"+value);
        }
    }
    if(typeof this.key !== 'undefined') {
        if(!(key.constructor === this.key)) {
            throw new Error("Invalid key type. Expected "+this.key+", given:"+key);
        }
    }
    this.list[key] = value;
}
SimpleMap.prototype.get = function(key) {
    if(typeof this.key !== 'undefined') {
        if(!(key.constructor === this.key)) {
            throw new Error("Invalid key type. Expected "+this.key+", given:"+key);
        }
    }
    return...