What Is an LLM?
A Large Language Model (LLM) like Claude or GPT predicts the next chunk of text given everything before it. It doesn't see words β it sees tokens (roughly word-pieces). Token count drives both cost and context limits, so estimating tokens is a real-world skill.
A crude-but-useful rule of thumb: ~1 token per word for plain English. We'll use a simple word-count estimate.
Your task
Write a function estimateTokens that takes a string and returns the number of
whitespace-separated words. An empty (or whitespace-only) string is 0.
β‘ 25 XP
solution.jsRuns in your browser
Loading editorβ¦
Tests4 to pass
"hello world" β 2
empty string β 0
whitespace only β 0
handles extra spaces
Run your code to check these.