Write a function. Test real cases. Improve your solution.
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.
[ " JavaScript Array Methods " ]
"javascript array methods"
[ "API\t\tError\n\nHandling" ]
"api error handling"
[ " \n\t " ]
""
[ "" ]
""
[ " CAFÉ: C++ / C# " ]
"café: c++ / c#"
[ "find a bug" ]
"find a bug"
Your code runs in your browser. These exercises use synchronous JavaScript functions and built-in data types; DOM access, network requests, and npm imports are unavailable. Runs stop after about four seconds. Test results support self-study and don’t certify proficiency.