I have the following array:
nombres = ["Violeta", "Andino", "Clemente", "Javiera", "Paula", "Pia", "Ray"]
a = nombres.select{ |ele|}
I would like to know what would be the instruction to create a
a array
different variable in the variable that contains only the elements that begin with the letter P .
You can use the method
start_with?
together withselect
:If you want it to ignore whether it's uppercase or lowercase, you could convert everything to lowercase (or uppercase) first; for instance:
Or you could also use regexp :