I want to format a string with not multiple space. String can have tab, carriage return or line feed.
Example 1:
hello
world
expacted result: hello
world
Example 2: hello world
expected result : 'hello world'
const formatString = (s) => {
const trimmed = s.trim();
const formated = trimmed.match(/\s/g)
return s.trim().replace(/\s+/g, ' ')
}
const str = `hello
world`
const result = formatString(str)
console.log(result)