Add or Remove 80/100
Здравейте! Как мога да проверя цял масив за една и съща "команда"? Пробвах с includes, every и нищо не стана. 100% е някаква проста проеверка, за която не се сещам. Чувствам се много тъп. Моля за помощ. :)
код:
условие:
Write a function that adds and removes numbers to/from an array. You will receive a command which can either be "add" or "remove";
The initial number is 1. Each input command should increase that number, regardless of what it is.
==> Upon receiving an 'add' command you should add the current number to your array.
==> Upon receiving the "remove" command you should remove the last entered number, currently existent in
the array.
Input
The input comes as array of strings. Each element holds a command.
Output
Print elements in a row, separated by single space. In case of an empty array, just print "Empty".
Examples
Input Output
[add, add, add, add] 1 2 3 4
[add, add, remove, add, add] 1 4 5
[remove, remove, remove] Empty