Created
September 16, 2020 11:05
-
-
Save imbhargav5/17d754344fade89cd5bb26827283e5b3 to your computer and use it in GitHub Desktop.
Queue with private class fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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