Skip to content

Instantly share code, notes, and snippets.

@imbhargav5
Created September 16, 2020 11:05
Show Gist options
  • Save imbhargav5/17d754344fade89cd5bb26827283e5b3 to your computer and use it in GitHub Desktop.
Save imbhargav5/17d754344fade89cd5bb26827283e5b3 to your computer and use it in GitHub Desktop.
Queue with private class fields
class Queue{
#array = []
enqueue(val){
return this.#array.push(val);
}
dequeue(){
return this.#array.shift();
}
isEmpty(){
return this.#array.length == 0
}
peek(){
if(this.isEmpty()){
return undefined;
}
return this.#array[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment