Then use splice if you're really concerned about it... will be O(n) with an n of 2.
Also, have you actually measured the performance cost of Delete... as I mentioned, you're optimizing by using an expensive call.
I'm not sure why one would do this over simply using an array... Delete in particular is a somewhat costly execution penalty.
class Queue {
constructor() {
this._items = [];
}
enqueue(item) {
this._items.push(item);
}
dequeue() {
return this._items.shift();
}
peek() {
return this._items[0];
}
get length() {
return this._items.length;
}
}
I think that Cloudflare workers are a great idea, and could be awesome for some projects. I'm not sure there's a self-hosted option as a migration strategy though... Short of an open platform to self-host at least for development, it just feels like the ultimate lock-in strategy.
I'm not sure why one would do this over simply using an array... Delete in particular is a somewhat costly execution penalty. class Queue { constructor() { this._items = []; } enqueue(item) { this._items.push(item); } dequeue() { return this._items.shift(); } peek() { return this._items[0]; } get length() { return this._items.length; } }If you *REALLY* don't like ternary operators... function ite(condition, thenValue, elseValue) { if (condition) return thenValue; return elseValue; }