export default class Dictionary {
private dataStore: any = new Array<any>(); // must be instatiated!
Dictionary() {
this.dataStore = [];
}
public add = (key: any, value: any) => {
this.dataStore[key] = value;
}
public find = (key: any) => {
return this.dataStore[key];
}
public getKeyByValue = (value: any) => {
for (const key in this.dataStore) {
if (this.dataStore[key] === value) {
return key;
}
}
return 'Not Found';
}
public remove = (key: any) => {
if (this.dataStore[key]) delete this.dataStore[key];
else return 'Not Found';
}
public showAll = () => {
for (const key in this.dataStore)
console.log(key + '->' + this.dataStore[key]);
}
}