JSFiddle - React, Tailwind, and code Playground

by kkdaily

HTML

<h1>
given a string with varying amounts of whitespace between words, edit the string so that there is only 1 whitespace character at most between words
</h1>

JavaScript

const example = 'there was   a dog   in  the   fog'

const removeWhiteSpace = (str) => {
	
  const words = str.split(' ');
  alert(words);
  const trimmed = words.join(' ');
  alert(trimmed)

}

removeWhiteSpace(example)