THE PRACTICE LIBRARY

JavaScript string practice and coding challenges

Practice JavaScript strings, arrays, and objects with browser-based challenges, visible tests, and optional hints. Start by cleaning a search query.

Try a beginner challengeLearn the concepts first

No account needed. Progress and drafts are saved on this device.

Start with strings: clean a search query

Search boxes receive pasted text, extra spaces, tabs, and mixed capitalization. Practice turning those different inputs into one consistent string. Check empty text and whitespace-only input as well as ordinary words. JavaScript strings are immutable, so return the transformed value.

The problem

A search box receives a string query. Return a lowercase string with leading and trailing whitespace removed and every internal run of whitespace replaced by one ordinary space. Tabs and newlines count as whitespace. Preserve punctuation and accented letters apart from normal JavaScript lowercasing. A query containing only whitespace becomes an empty string. The input is always a string.

Example input" JavaScript Array Methods "Expected result"javascript array methods"

Write your answer in the editor, then choose Run tests. Each check shows what was expected and what your code returned. Reveal hints one at a time; the solution stays behind the solution button.

Open clean a search query

JavaScript challenges

12 of 12
JavaScriptIntermediate

Deduplicate issue labels

Given an array of strings, return the issue labels after trimming their edges, dropping empty labels, and removing case-insensitive duplicates.

Arrays · Sets · Normalization

Open challenge
JavaScriptIntermediate

Group a support queue

Given tickets with an id string and status string, return an array of {status, ids} groups.

Maps · Grouping · Ordering

Open challenge
JavaScriptIntermediate

Update a cart without mutation

Given an items array with unique sku strings and positive integer quantity fields, update the item matching sku.

Immutability · Arrays · Object copying

Open challenge
JavaScriptIntermediate

Build reliable pagination

Return {items, page, totalPages, hasNext} for a requested page of a results array.

Array slicing · Boundary conditions · Pagination

Open challenge
JavaScriptAdvanced

Merge calendar busy windows

A calendar export contains unsorted busy windows [start, end], measured in integer minutes, with start < end.

Intervals · Sorting · Immutability

Open challenge
JavaScriptIntermediate

Rank a command palette

Given command objects {id, title} and a query string, return matching ids for a command palette.

Filtering · Sorting · Stable ordering

Open challenge
JavaScriptAdvanced

Find the busiest event window

Given unsorted nonnegative integer event timestamps and a positive integer windowMs, find the busiest fixed-length time window.

Sliding windows · Sorting · Boundary conditions · Data analysis

Open challenge