Hello,

you can try using a Map with unique keys. Map operations are guaranteed to be 
sublinear on average, and new entries are added to the end.

Then you only need a trivial wrapper for better abstraction:

```js
class Queue {
  constructor() {
    this._map = new Map();
  }
  push(value) {
    this._map.set({}, value);
  }
  pop() {
    var first = this._map.entries().next();
    if (first.done) return;
    this._map.delete(first.value[0]);
    return first.value[1];
  }
  get size() {
    return this._map.size;
  }
}
var q = new Queue();
q.push(1);
q.push(2);
q.pop(); // 1
q.push(3);
q.pop(); // 2
q.pop(); // 3
q.pop(); // undefined
```

-- Oriol

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to