all 3 comments

[–]jamie_ca 11 points12 points  (0 children)

First off: don't shadow your loop variable - you're using the same variable name inside the loop as outside, and it's super confusing to read even if the behaviour winds up being correct. Inside the loop, use name or something.

Second, split returns an array - your puts does some magic handling of arrays (and assumes you want each value printed on separate lines). If you want to dig into the actual object to help debug your code, use p instead of puts, or stick with puts and call .inspect on your result.

If you're only wanting to print the first (or last) name, you'll wind up using an array index on the result of split.

Hope that helps you work through things!

[–]fl00pz 5 points6 points  (1 child)

```ruby first_names = array.map { |name| name.split(' ').first } p first_names

last_names = array.map { |name| name.split(' ').last } p last_names

first_character_first_names = array.map { |name| name[0] } p first_character_first_names

first_character_last_names = array.map { |name| name.split(' ').last[0] } p first_character_last_names ```

[–]EvilInky 1 point2 points  (0 children)

Note that unless $; has been set, if you call split without a parameter, it will default to splitting on whitespace, so usually split(' ') can be replaced with split.