Skip to content

Instantly share code, notes, and snippets.

@mikalai-yankouski
Last active November 27, 2018 13:00
Show Gist options
  • Save mikalai-yankouski/b272d6f7c84a1b0aec8f2970b4f50065 to your computer and use it in GitHub Desktop.
Save mikalai-yankouski/b272d6f7c84a1b0aec8f2970b4f50065 to your computer and use it in GitHub Desktop.
Дана строка в которой записаны слова через пробел. Необходимо упорядочить слова по количеству букв в каждом слове.
require 'faker'
random_string = Faker::Lorem.words(10).join(" ") #Faker возвращает array, поэтому join в строку
sorted_string = random_string.split.sort {|x,y| x.length <=> y.length}
puts "String: #{random_string.inspect}"
puts "Sorted string: #{sorted_string}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment