Implementation of some simple data structure in JavaScript