Text processing/1: Difference between revisions

→‎{{header|Ruby}}: clarified name
(→‎{{header|Ruby}}: adding a very different implementation)
(→‎{{header|Ruby}}: clarified name)
Line 3,077:
good_readings = all_readings.select(&:flag)
all_streaks = all_readings.slice_when {|bef, aft| bef.flag != aft.flag }
bad_streakworst_streak = all_streaks.reject {|grp| grp.any?(&:flag)}.sort_by(&:size).last
 
total = good_readings.map(&:value).reduce(:+)
Line 3,086:
puts "Average %.3f" % total./(num_readings)
puts
puts "Max run of #{bad_streakworst_streak.count} consecutive false readings from #{bad_streakworst_streak.first.date} until #{bad_streakworst_streak.last.date}"
</lang>
 
Anonymous user