Exercise · Array methods · lesson 11 of 12
Exercise: checking ages
Write two functions for an array of ages ages:
function firstAdult(ages, minAge)returns the first age, in order, that is not less thanminAge, the age of majority, which differs between countries;function allTeens(ages)returnstrueif every age is from13to19inclusive, andfalseotherwise.
Examples:
firstAdult([12, 17, 21, 30], 18)→21firstAdult([16, 19, 25], 21)→25firstAdult([5, 10, 17], 18)→undefinedallTeens([13, 15, 19])→trueallTeens([14, 20, 16])→false
Constraints: ages holds 0 to 10 integers from 0 to 120, and minAge is an integer from 14 to 21; if no age fits, an empty array included, firstAdult returns undefined; for an empty array allTeens returns true.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.