Skip to content
Advertisement

pushing and poping into new list

I am trying to make a loop that if the program sees a letter or number it will push(x) into a new list and if it sees an asterisk * it must pop(). It is more of a stack algorithm where the first letter or number in is the last one out. FILO First in last out

For example

If the program is given the following array

JavaScript

It should output

JavaScript

or a letter input

JavaScript

letter Output

JavaScript

How can I implement this?

Advertisement

Answer

This should work:

JavaScript
['2', '4', '3', '1']
['a', 't', 'o', 'e', 'd', 'f']
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement