Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69e2383af7832c8032603b90 Challenge 274: Oldest Person 29 challenge-274

--description--

Given an array of objects, each with a "name" and "age" property, return an array containing the name of the oldest person.

If multiple people share the oldest age, return all of their names in the order they appear in the input.

--hints--

get_oldest([{ "name": "Brenda", "age": 40 }]) should return ["Brenda"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_oldest([{"name": "Brenda", "age": 40}]), ["Brenda"])`)
}})

get_oldest([{ "name": "Alice", "age": 30 }, { "name": "Bob", "age": 25 }]) should return ["Alice"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_oldest([{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]), ["Alice"])`)
}})

get_oldest([{ "name": "Allison", "age": 25 }, { "name": "Bill", "age": 30 }, { "name": "Carol", "age": 30 }]) should return ["Bill", "Carol"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_oldest([{"name": "Allison", "age": 25}, {"name": "Bill", "age": 30}, {"name": "Carol", "age": 30}]), ["Bill", "Carol"])`)
}})

get_oldest([{ "name": "George", "age": 50 }, { "name": "Shirley", "age": 42 }, { "name": "Beth", "age": 48 }, { "name": "Holly", "age": 50 }, { "name": "Kevin", "age": 44 }, { "name": "Frank", "age": 47 }, { "name": "Zach", "age": 50 }, { "name": "Jennifer", "age": 43 }]) should return ["George", "Holly", "Zach"].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_oldest([{"name": "George", "age": 50}, {"name": "Shirley", "age": 42}, {"name": "Beth", "age": 48}, {"name": "Holly", "age": 50}, {"name": "Kevin", "age": 44}, {"name": "Frank", "age": 47}, {"name": "Zach", "age": 50}, {"name": "Jennifer", "age": 43}]), ["George", "Holly", "Zach"])`)
}})

--seed--

--seed-contents--

def get_oldest(people):

    return people

--solutions--

def get_oldest(people):
    max_age = max(p["age"] for p in people)
    return [p["name"] for p in people if p["age"] == max_age]