Tell us what’s happening:
I am unable to go further with this exercise. Looking for a help.
Your code so far
class CircularQueue {
constructor(size) {
this.queue = [];
this.read = 0;
this.write = 0;
this.max = size - 1;
while (size > 0) {
this.queue.push(null);
size--;
}
}
print() {
return this.queue;
}
enqueue(item) {
if (this.queue[this.write] == null) {
this.queue[this.write] == item;
this.write++;
this.write %= this.queue.length;
console.log(this.write);
return item;
}
return null;
// Only change code above this line
}
dequeue() {
// Only change code below this line
let removedItem = null;
if (this.queue[this.read] !== null) {
removedItem = this.queue[this.read];
this.queue[this.read] = null;
this.read++;
this.read %= this.queue.length;
}
return removedItem;
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/data-structures/create-a-circular-queue/