JSFiddle - React, Tailwind, and code Playground

by XGundam05

HTML

<div id="testing"></div>

JavaScript

Array.prototype.binarySearch = function(value){
    var index = 0;
    var max = this.length - 1;
    var min = 0;
    while(max >= min){
        index = min + ((max - min) / 2);
        index = index | 0;
        if(this[index] == value)
            return index;
        
        if(value > this[index]){
            min = index + 1;
        }
        else{
            max = index - 1;
        }
    }
    
    return -1;
};

function Dictionary(){
    this.keys = [];
    this.values = [];
    this.length = 0;
}

Dictionary.prototype.hasKey = function(key){
    var index = this.keys.binarySearch(key);
    
    return index > -1;
};

Dictionary.prototype.get = function(key){
    var index = this.keys.binarySearch(key);
    if(index > -1)
        return this.values[index];
    
    return undefined;
};

Dictionary.prototype.add = function(key, value){
    if(!this.hasKey(key)){
        this.keys.push(key);
        this.keys.sort();
        
        var index = this.keys.binarySearch(key);
        this.values.push(value);
        if(index > -1){
            for(var i = index; i < this.values.length - 1; i++){
                var tmp = this.values[i];
                this.values[i] = this.values[this.values.length - 1];
                this.values[this.values.length - 1] = tmp;
            }
        }
        this.length++;
    }
};

Dictionary.prototype.remove = function(key){
    var index = this.keys.binarySearch(key);
    if(index > -1){
        for(var i = this.keys.length - 1; i > index; i--){
            var kTmp = this.keys[i];
            var vTmp = this.values[i];
            
            this.keys[i] = this.keys[index];
            this.values[i] = this.values[index];
            
            this.keys[index] = kTmp;
            this.values[index] = vTmp;
        }
        
        this.keys.pop();
        this.values.pop();
        this.length--;
    }
};

var dict = new Dictionary();
dict.add('alpha', 3);
dict.add('theron', 'varchar');
dict.add('elmo',...