ST
Ruby
Back to Course Loading Ruby…

Filter active users

Ruby Junior

Implement active_users(users). Given an array of hashes where each hash has a :name and a :active key, return only the active ones, sorted alphabetically by name.

The function should return [] if the input is empty or no users are active.

Example 1:

Input:  [{ name: "Karim", active: true }, { name: "Sara", active: false }]
Output: [{ name: "Karim", active: true }]

Example 2:

Input:  [{ name: "Zoe", active: true }, { name: "Alice", active: true }]
Output: [{ name: "Alice", active: true }, { name: "Zoe", active: true }]

Constraints:

  • users is an Array of Hashes
  • 0 ≤ users.size ≤ 10⁴
Ruby
Ruby loads on first visit (≈34MB, cached after). When ready, write your solution and click Submit.