Stand in Line [Queueing]

Published by Gray Jackel in

Write a function that takes a vector and an integer as arguments. Add the number to the end of the vector, then remove the first element of the vector. The function should then return the updated vector.

Examples

nextInLine({5, 6, 7, 8, 9}, 1) ➞ {6, 7, 8, 9, 1}

nextInLine({7, 6, 3, 23, 17}, 10) ➞ {6, 3, 23, 17, 10}

nextInLine({1, 10, 20, 42 }, 6) ➞ {10, 20, 42, 6}

nextInLine({}, 6) ➞ {}

Notes

  • For an empty vector input, return an empty vector.
  • This challenge also is an introduction to the concept of queueing.
Watch a quick demo on how Edabit works.