JSFiddle - React, Tailwind, and code Playground
by Steven Senkus
JavaScript
function Dictionary() {
this.dataStore = new Array();
}
Dictionary.prototype.add = function (key, value) {
this.dataStore[key] = value;
};
Dictionary.prototype.find = function (key) {
return this.dataStore[key];
};
Dictionary.prototype.remove = function (key) {
delete this.dataStore[key];
}
Dictionary.prototype.showAll = function () {
console.log('SHOWALL');
for (var key in Object.keys(this.dataStore)) {
console.log(key + " -> " + this.dataStore[key]);
}
};
Dictionary.prototype.count = function () {
var n = 0;
console.log(this.dataStore, Object.keys(this.dataStore));
for (var key in Object.keys(this.dataStore)) {
n++;
}
return n;
};
Dictionary.prototype.clear = function () {
for (var key in Object.keys(this.dataStore)) {
console.log(key, this.dataStore[key], this.find(key));
delete this.find(key)
}
};
var d = new Dictionary();
d.add('keya', 'vala');
d.add('keyb', 'valb');
d.add('keyc', 'valc');
d.clear();
d.showAll();