Recap - Range Practice
Part of the Logic & Flow section of Coddy's Ruby journey — lesson 9 of 56.
One challenge that pulls together inclusive ranges, range methods, and the case + range pattern.
Challenge
EasyRead two integers (two lines of input): start and end_value. For every number in the inclusive range start..end_value, print one line in the format:
<n>: <label>Where label is determined by a case on the number itself:
1..3→small4..6→medium7..10→large- anything else →
out of scale
Then, on a final line, print the count of values that landed in 1..10 using include?.
For input 2 then 5, the output is:
2: small
3: small
4: medium
5: medium
In scale: 4Try it yourself
start = gets.to_i
end_value = gets.to_i
# TODO: iterate the range, print labels, and report how many were in 1..10
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