Skip to content

Instantly share code, notes, and snippets.

@Alxandr
Created September 3, 2012 19:05
Show Gist options
  • Select an option

  • Save Alxandr/3612448 to your computer and use it in GitHub Desktop.

Select an option

Save Alxandr/3612448 to your computer and use it in GitHub Desktop.
Javascript table
function table()
{
var keys = [],
vals = [];
function indexOf(key) {
return keys.indexOf(key);
}
function get(key) {
var index = indexOf(key);
if(index == -1) {
throw new Error('Key not found');
}
return vals[index];
}
function set(key, val) {
var index = indexOf(key);
if(index == -1) {
index = keys.length;
keys.push(key);
vals.push(val);
}
vals[index] = val;
}
return {
get: get,
set: set
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment