Implementation for some simple data structure in JavaScript