jugosack / queue-jugosack-mob-pro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to solve this challenge?

  1. Read the "Challenge description" below.
  2. Make changes to the challenge.js file.
  3. Commit your changes.
  4. Wait for the result of the "GitHub Classroom Workflow" action. If it is green - congratulations, you solved this challenge! If not - try again!
  5. You can watch an example of how to solve a challenge in the video linked in the theoretical lesson preceding this challenge.

Challenge description

Queue

Create a Queue with the two methods add and remove. Use your LinkedList class to keep track of the elements internally. In this challenge, there's one more detail: If remove is called on the empty Queue, return -1.

Explanation of solution

Example

This is an example of a test case:

const queue = new Queue()
queue.add(3)
queue.add(5)
console.log(queue.remove)
// => 3

queue.add(2)
queue.add(7)
console.log(queue.remove())
// => 5

console.log(queue.remove())
// => 2

console.log(queue.remove())
// => 7

console.log(queue.remove())
// => -1

The numbers come out in the order they went in, and the final remove returns a -1 since the queue is empty.

Troubleshooting

If you cannot see any auto-grading workflows on the Actions page, learn how to fix it in this repo.

About

License:MIT License


Languages

Language:JavaScript 100.0%