Create Alt Dictionary class - Node.js Data Structure

Node.js examples for Data Structure:Dictionary

Description

Create Alt Dictionary class

Demo Code

function AltDict() {
  this.data = {};/*from  www. ja  va 2 s .  c o m*/
  return this;
}

AltDict.prototype.get = function(key) {
  key = "k-" + key;
  if(key in this.data){
    return this.data[key];
  } else {
    return null;
  }
};

AltDict.prototype.put = function(key, value) {
  key = "k-" + key;
  this.data[key] = value;
};

AltDict.prototype.values = function() {
  var data = this.data;
  var keys = Object.keys(this.data);
  return keys.map(function(key) {
    return data[key];
  });
};

Related Tutorials