Skip to main content
πŸ€– Learn AI: Build with LLMs

The Context Window

An LLM can only attend to a limited context window. For long chats you keep the most recent messages and drop older ones. A simple sliding window keeps the last N turns.

messages.slice(-3); // the last 3 messages

Your task

Write recentMessages(messages, maxCount) returning the last maxCount messages (or all of them if there are fewer).

⚑ 35 XP
solution.jsRuns in your browser
Loading editor…
Tests3 to pass
keeps last 2
fewer than max
empty

Run your code to check these.