Create Double Dictionary class - Node.js Data Structure

Node.js examples for Data Structure:Dictionary

Description

Create Double Dictionary class

Demo Code

function DoubleDict() {
  return this;//  w w  w . j av  a 2  s  .  c  o m
}

DoubleDict.prototype.get = function(a, b) {
  var d = this[a] || null;
  return d===null ? null : (d[b] || null);
};

DoubleDict.prototype.set = function(a, b, o) {
  var d = this[a] || null;
  if(d===null) {
    d = {};
    this[a] = d;
  }
  d[b] = o;
};


function escapeWhitespace(s, escapeSpaces) {
  s = s.replace("\t","\\t");
  s = s.replace("\n","\\n");
  s = s.replace("\r","\\r");
  if(escapeSpaces) {
    s = s.replace(" ","\u00B7");
  }
  return s;
}

Related Tutorials