Created
April 3, 2019 16:01
-
-
Save maksbd19/c4962d218e1c1d33c0a7ab1d2e6af50f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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