Skip to content

Instantly share code, notes, and snippets.

@maksbd19
Created April 3, 2019 16:01
Show Gist options
  • Save maksbd19/c4962d218e1c1d33c0a7ab1d2e6af50f to your computer and use it in GitHub Desktop.
Save maksbd19/c4962d218e1c1d33c0a7ab1d2e6af50f to your computer and use it in GitHub Desktop.
const hash = {};
// to get the value for a particular index
const get = index => typeof hash[index] !== "undefined" ? hash[index] : null;
// add a new value in a particular index
const set = (index, data) => {
if( typeof hash[index] === "undefined"){
hash[index] = [];
}
hash[index].push(data);
}
// remove a value from a particular index
const pop = (index, value) => {
if( typeof hash[index] === "undefined"){
return true;
}
const valueIndex = hash[index].indexOf(value);
if(valueIndex > -1){
hash[index].splice(valueIndex, 1);
}
return true;
}
// remove all values stored in a particular index
const remove = index => {
if( typeof hash[index] !== "undefined"){
delete hash[index];
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment