I am attempting to remove ""
& " "
from the back of a string array until the last item contains some text, but my implementation isn't picking up " "
.
My implementation so far:
var array = ["A", "B", "", "C", "D", " ", " ", ""]
while true {
if (array.last == " " || array.last == "") {
array.removeLast()
} else {
break
}
}
My desired output is
["A", "B", "", "C", "D"]
, but my current output is
["A", "B", "", "C", "D", " ", " "]
, where the while
loop simply breaks
after encountering " "
Any advice why is it not picking up the " "
?