Implement prototype(text, pattern) and solve(text, pattern). Return every matching start as an ascending Number index, including overlaps. Compare Unicode code points exactly; do not fold or normalize.

On "ababa", "aba", return [0, 2]. On "abc", "", return [0, 1, 2, 3]. Empty pattern matches every code-point boundary; nonempty pattern in empty text returns [].

Prototype: compare each start character by character. Final: KMP with O(n+m) preprocessing/search and O(m) auxiliary space excluding output. A text iterator avoids materializing a full text array. Preserve inputs; no additional validation errors.

All numeric inputs and finite arithmetic results in this lesson are safe-integer Numbers. Use null for documented absence, not undefined or a numeric sentinel. Return actual booleans where the contract requires them. Do not add validation requirements beyond the documented inputs.

String positions and lexicographic ordering in this exercise use Unicode code points. Array.from(text) and string iteration expose code points; text.length, indexing, and default string sorting use UTF-16 code units. Do not substitute locale collation or add Unicode normalization.

Run with Node.js 20+ from this directory:

Shell
node main.mjs --stage prototype
node main.mjs --stage final

Edit exercise.mjs; keep main.mjs unchanged. Both stages begin as unfinished learner functions. The website uses the same test functions in a separate browser worker. Tests check deterministic examples, boundaries, documented validation, input preservation, and stage-specific cases. Passing tests does not prove the required time complexity.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.