Your 20-minute checkpoint
Close the earlier examples. Spend two minutes writing the inputs, expected outputs, and steps in plain language. Use about eight minutes to build and test, then five to explain your choices and try the variation. Taking longer is normal: these are study budgets, not speed tests.
Compose filtering, ordering, and formatting. This problem deliberately changes the setting so you practice choosing the tools yourself.
Acceptance cases before you code
Before you write code, decide what recommend should return for each case below. Then call your function once per case and print the result. An empty result and an exact-limit session catch different mistakes.
| Case to try | What your result should demonstrate |
|---|---|
| No eligible session | Return empty text rather than reading an absent first item |
| Session exactly at the limit | Include it |
| Two eligible sessions supplied in descending duration | Return ascending recommendations while the original array keeps its order |
When everything works, remove the copy before sort on purpose and find the case that notices. Put it back, then say in one sentence which rule the mistake broke. If you cannot remember how to do a step, revisit that lesson before opening the solution.
A recommendation function
Write recommend(sessions, maxMinutes). Select sessions no longer than the limit, order them shortest first, and return topic names joined by a comma. Preserve the original order.
const sessions = [
{ topic: "Objects", minutes: 30 },
{ topic: "Loops", minutes: 10 },
{ topic: "Arrays", minutes: 20 }
];Hint 1: the idea
Select records first, order the selected array, then transform records into names.
Hint 2: a first step
filter returns a new array; sort that result with a minutes comparator.
Show one solution
function recommend(sessions, maxMinutes) {
const eligible = sessions.filter(item => item.minutes <= maxMinutes);
const ordered = eligible.sort((a, b) => a.minutes - b.minutes);
const topics = ordered.map(item => item.topic);
return topics.join(", ");
}
const sessions = [
{ topic: "Objects", minutes: 30 },
{ topic: "Loops", minutes: 10 },
{ topic: "Arrays", minutes: 20 }
];
console.log(recommend(sessions, 20));
console.log(sessions[0].topic);Loops, Arrays
ObjectsTry limits of 9, 10, and 30. The first returns an empty string by this contract. Add a display fallback at the call site if needed.
Change the requirements
Try limits of 9, 10, and 30. The first returns an empty string by this contract. Add a display fallback at the call site if needed.
Decide what to revisit
- Can you explain each variable and the reason for each condition?
- Did you check an empty, boundary, or changed input rather than only the supplied one?
- Can you rebuild the essential part after closing the solution?
If you needed a hint, record the specific missing idea and revisit that lesson. Marking a page done records progress; it does not replace practice. Begin tomorrow by rebuilding one small part from memory.
Completion is saved in this browser only. It does not measure mastery.