Search⌘ K
AI Features

Solution: Sorting Children's Names

Understand how to create and manipulate arrays in Ruby by collecting children's names from user input, sorting them alphabetically, and outputting them as a comma-separated string. This lesson guides you through array creation, data insertion, and sorting techniques to manage composite data types effectively.

We'll cover the following...

Solution

array = []
input = nil
puts "Enter child names in class: (0 to finish)" 
until input == "0"
    input = gets.chomp 
    if input != "0"
        array << input 
    end
end
puts "Children names in order:"
puts array.sort.join(", ")
Sorting children's names

Explanation

  • Line 1: We create ...