Menu
Coddy logo textTech

Data Transformer

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

The capstone challenge, reshape a dataset into a summary report. Combine filtering, mapping, grouping, error handling, and method definition into one program.

challenge icon

Challenge

Medium

The array students is given. Each entry is a hash with :id, :grades (an array of integers, possibly empty), and :subjects (an array of strings).

Define a method transform_dataset(students) that returns a hash with two keys:

  • :qualified_ids: sorted array of :ids of students who have at least one grade and all grades strictly above 70 (use all?).
  • :subject_counts: a hash mapping each subject taken by the qualified students to the number of qualified students taking it.

If a student's :grades array is empty, they are not qualified, silently skip them.

Then call the method and print:

  1. The qualified IDs joined with , , prefixed with Qualified: . If none, print Qualified: (none).
  2. One line per subject (sorted alphabetically) in the format <subject>: <count>.

For the default students, the output is:

Qualified: S1, S4
biology: 1
history: 1
math: 2
physics: 1

Try it yourself

students = [
  { id: "S1", grades: [85, 92, 78], subjects: ["math", "physics"] },
  { id: "S2", grades: [65, 80, 90], subjects: ["math", "biology"] },
  { id: "S3", grades: [],          subjects: ["art"] },
  { id: "S4", grades: [88, 95],    subjects: ["math", "biology", "history"] },
  { id: "S5", grades: [70, 75],    subjects: ["chemistry"] }
]

# TODO: def transform_dataset(students), return { qualified_ids:, subject_counts: }
# TODO: print qualified IDs and subject counts
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Logic & Flow