🛡️🛡️Escudo anti-spoilers🛡️🛡️
Mi solución al reto:
import { Mail } from "./mail";
export class Queue {
constructor() {
this.first = null;
this.last = null;
this.length = 0;
}
enqueue(from, to, body, subject) {
let newMail = new Mail(from, to, body, subject)
if (this.length == 0) {
this.first = newMail
this.last = newMail
} else {
this.last.next = newMail
this.last = newMail
}
this.length++
}
dequeue() {
let r = this.first;
if (this.first === this.last)
this.last = null;
this.first = this.first.next;
this.length--
delete r.next
return r;
}
peek() {
if (!this.first) return null
return {
from: this.first.from,
to: this.first.to,
body: this.first.body,
subject: this.first.subject
}
}
size() {
return this.length
}
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?