Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

function nextInLine(arr, item) {

arr.push(item); izmjenjeno

The push() method adds new items to the end of an array.

The push() method changes the length of the array.

The push() method returns the new length.

return arr.shift(); izmjenjeno

The shift() method removes the first item of an array.

The shift() method changes the original array.

The shift() method returns the shifted element.

dok
The pop() method removes (pops) the last element of an array.

The pop() method changes the original array.

The pop() method returns the removed element.

// Setup
const testArr = [1, 2, 3, 4, 5];

// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));

In Computer Science a queue is an abstract Data Structure where items are kept in
order. New items can be added at the back of the queue and old items are taken off
from the front of the queue.

Write a function nextInLine which takes an array (arr) and a number (item) as
arguments.

Add the number to the end of the array, then remove the first element of the array.

The nextInLine function should then return the element that was removed.

You might also like