const normalizeWhitespace = (text) => { // Replace multiple whitespace characters (including newlines, tabs) with a single space // Then trim leading/trailing spaces return text.replace(/\s+/g, ' ').trim(); }; console.log(normalizeWhitespace(" Hello World! This is a test. ")); // Expected: "Hello World! This is a test." console.log(normalizeWhitespace("Tabs\t and\tnewlines work.")); // Expected: "Tabs and newlines work." console.log(normalizeWhitespace(" No leading or trailing spaces ")); // Expected: "No leading or trailing spaces"