I am looking for a way to keep track of a list of strings with a maximum length.
For instance, I need to maintain a list with a maximum length of 3. I want to add new items to the list as long as its length is less than 3. However, once the length reaches 3 and I try to add a new item, I want to remove the oldest entry from the list.
const list = ["A", "B", "C"]
list.push("D")
// Your logic here
// The expected output should be ["B", "C", "D"]
console.log(list)
Does anyone have any suggestions on how to accomplish this?