Your 15-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 practise choosing the tools yourself.
A small warm-up
Before the main task, predict this familiar idea from today’s work. If it is unclear, revisit the relevant teaching lesson first.
Check the foundation
Say why each line appears, not just what it prints.
const double = value => value * 2;
console.log([2, 3].map(double).join(", "));Check your prediction
4, 6Use this only as a warm-up. The main task needs you to combine several decisions.
Acceptance cases before you code
Write a small test plan before implementing recommendation order and ownership. These cases extend the brief; they are not a second worked solution. Predict the expected behavior independently, then test through the public function. A good ordinary example and a good boundary example should catch different possible 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 |
| Unsorted input with distinct durations | Return shortest-first names and preserve source order |
After the core task passes, deliberately break one rule and identify the case that notices it. Restore the implementation and explain the failure in terms of the contract, not the number of assertions. If a case requires a concept you have not recalled, revisit the relevant 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.