How do I get rid of whitespaces and blank items in an array
names = ["alice", "", "bob", " ", "yankee"]
desired result should be
["alice", "bob", "yankee"]
How do I get rid of whitespaces and blank items in an array
names = ["alice", "", "bob", " ", "yankee"]
desired result should be
["alice", "bob", "yankee"]
If you try this below it will provide you with a new array assigned to newNames that does not include the empty elements.
newNames = names.reject { |n| n.empty? }