Capstone: normalizing usernames
The last lesson validated one username. Real input arrives as a batch - a
signup list, an import file, a CSV column - and the job is usually "keep the
valid ones, and clean them up." Regex answers the first half; ordinary array
methods answer the second.
array.filter(fn) keeps only the items where fn returns true; array.map(fn)
transforms what's left. Chain them and a messy list becomes exactly the
usernames you can actually store: valid, and consistently lowercased.
Your task: write normalizeUsernames(list), returning only the valid
usernames from list (3-16 characters, starts with a letter, only letters,
digits, or underscores after that - same shape as the last lesson), each
converted to lowercase, in their original order.
You'll practice:
Reusing a validation regex inside .filter()
Chaining .filter() and .map() to clean up a list
Show a hint
Show solution
Previous