templates-mo
Version:
Templates is a scaffolding framework that makes code generation simple, dynamic, and reusable. Generate files, parts of your app, or whole project structures—without the repetitive copy-pasting
41 lines (40 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Queue = void 0;
const stack_1 = require("./stack");
class Queue {
constructor() {
this.inbox = new stack_1.Stack();
this.outbox = new stack_1.Stack();
}
enqueue(...args) {
args.forEach((item) => {
this.inbox.push(item);
});
}
dequeue() {
if (this.outbox.size() === 0) {
while (this.inbox.size() !== 0) {
// cannot be null because size is not zero
this.outbox.push(this.inbox.pop());
}
}
return this.outbox.pop();
}
size() {
return this.inbox.size() + this.outbox.size();
}
peek() {
return this.outbox.next() || this.inbox.next();
}
log(filter) {
const cb = filter || ((c) => c);
const queue = this.inbox
.stack()
.reverse()
.concat(this.outbox.stack())
.map(cb);
console.log('queue: ', queue);
}
}
exports.Queue = Queue;