Tell us what’s happening:
I don’t know why the below code not passing the priority queue in free code camp, Can anyone please let me know? Also why the front method is not included in the test cases?
Your code so far
class PriorityQueue {
constructor(){
this.data = []
}
print(){
console.log(this.data)
}
enqueue(item){
if(this.isEmpty()){
this.data.push(item)
}else{
let currIndexToInsert
for(let i = 0; i<this.data.length; i++){
let currItemPriority = this.data[i][1]
if(currItemPriority === item[1]){
currIndexToInsert = i
}
}
if(!isNaN(currIndexToInsert)){
this.data.splice(currIndexToInsert + 1, 0, item)
}else{
this.data.push(item)
}
}
}
dequeue(){
return this.data.shift()[0]
}
size(){
return this.data.length
}
front(){
return this.data[this.data.length - 1][0]
}
isEmpty(){
return this.data.length === 0
}
}
**Link to the challenge:**
https://www.freecodecamp.org/learn/coding-interview-prep/data-structures/create-a-priority-queue-class