It is important to first assess the length of a string before proceeding with any actions.
// Verify if the length of the last element is greater than 1
if(queue[queue.length - 1].length > 1){
// Trim the last character and update the string
queue[queue.length - 1] = queue[queue.length - 1].slice(1, -1);
} else {
// If not, remove the last element
queue.pop();
}
In an alternative approach, you can remove the last element, evaluate if its string length exceeds 1, then trim the last character and add it back to the array.
// Extract the last element from the array
let last = quene.pop();
// Check if the element's length is greater than 1
if(last.length > 1){
// Remove the final character from the string and reintroduce it to the array
queue.push(last.slice(1, -1))
}