Menu
Coddy logo textTech

Recap - Word Stats

Part of the Logic & Flow section of Coddy's Swift journey — lesson 27 of 56.

challenge icon

Challenge

Medium

Read a single line of input: a sentence (words separated by spaces). Compute and print, on separate lines:

  1. The number of words longer than 3 characters
  2. The total length, in characters, of all words longer than 3 (combine filter, map, reduce)
  3. The longest word in upper case. If two words tie, return the first one. Use reduce with the empty string as the initial accumulator.

For input swift makes data pipelines fun, the output is:

4
23
PIPELINES

Try it yourself

let words = readLine()!.components(separatedBy: " ")

// TODO: count > 3 chars; total length of those; longest word uppercased

All lessons in Logic & Flow