Recap - String Weaver
Part of the Logic & Flow section of Coddy's Ruby journey — lesson 5 of 56.
Time to combine what you've learned: trimming, interpolation, iteration, and split/join all in one challenge.
Challenge
EasyRead one line of input, a sentence. Print three lines:
- The number of words (split on whitespace)
- The sentence with every word reversed but in the same order. For
hello world, this isolleh dlrow. - The sentence joined with hyphens, in lowercase. For
Hello World, this ishello-world.
For input Hello Ruby World, the output is:
3
olleH ybuR dlroW
hello-ruby-worldTry it yourself
input = gets.chomp
# TODO: print the three required lines
All lessons in Logic & Flow
1Strings In Depth
String Methods OverviewString InterpolationIterating Over StringsSplit and JoinRecap - String Weaver4Blocks, Procs & Lambdas
What is a Block?do..end vs BracesThe yield KeywordBlock ParametersProcs and LambdasRecap - Custom Iterator7Hashes Part 2
Hash.new with DefaultsIterating HashesNested HashesMerging and TransformingRecap - Frequency Counter10Project - Student Records
Project OverviewAdd Student5Enumerable Powerhouse
Select and RejectChaining MapReduce / Injectcount, all?, any?, none?group_by and partitionsort_by, min_by, max_byRecap - Data Pipeline8Advanced Decision Making
Case with Classes & RegexMulti-value whenTernary OperatorInline if / unlessRecap - Grade Classifier