0
votes

I am writing a function queue which takes an array (arr) and a number (item) as arguments. Then I add the number to the end of the array, and remove the first element of array. The function should then return the element that was removed.

function queue(arr, item) {

arr.push(item);
var removedItem = arr.shift();

return removedItem;  
}   

Then i get this error: RangeError: maximum call stack size exceeded.

Can anyone explain me what is going wrong? In my eyes (beginner), the code looks okay? Thanks in advance!

1
Is the function queue called infinitely? maybe inside a l0000000p - Tushar
add the code of where you call it - Nitsan Baleli
There is no reason for such error in the provided code. Should be in another place. :) - Microfed
Thanks all! It is a challenge in Free Code Camp, but with a 'bug' I guess. When i refreshed the page, the function worked.. - Royal
I'm voting to close this question as off-topic because the page just needed a refresh (see self-answer) - Paul S.

1 Answers

0
votes

This is a challenge in Free Code Camp.

The solution in my answer is right. I refreshed the page and it worked.