From the course: Data Structures in JavaScript: BSTs, Queues, and Stacks
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Solution: How to dequeue and enqueue - JavaScript Tutorial
From the course: Data Structures in JavaScript: BSTs, Queues, and Stacks
Solution: How to dequeue and enqueue
(upbeat music) - [Instructor] Welcome to the solution for this challenge. For this challenge, you were to write a function that would dequeue the last element in a queue. Let's take a look at the code. On line 10, you see that there's a cla rephrase. On line 10 the class Queue was declared using a constructor function. On line 15, we see the function enqueue. On line 19, we see the function dequeue. Alright, and looking now on line 24, we see the instantiation of a new queue and it is given the label of testQ. On line 25, we see that testQ.enqueue is on enqueuing the number five to the queue that has the label testQ. Then on line 26, we see there's the enqueuing of the number 17 to the queue. And then on line 27, we see the enqueuing of the number 22 to the queue. Again, your directions were to dequeue the last element of the queue. Taking a look back at your code on lines 19 through 21, there is a method that you could have used or a function you could have used that was given to you…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.