create a fixed-length queue array in javascript

You’ve basically got it in your first code block there, it just requires a slight adjustment of the logic. If it’s a queue then you should always push the new number. You should then test if the length is greater than 4, and if it is, then use .shift() as you have done here to remove the first element.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top