String.prototype.replaceintermediate'foo bar foo'.replace('foo', 'baz') // β 'baz bar foo'
'hello'.replace(/[aeiou]/g, '*') // β 'h*ll*'Use replace() to replace the first occurrence of a pattern; use a /g regex to replace all occurrences.
Use $1, $2, etc. in the replacement string to reference captured groups.
Challenge: Implement swapWords(str) that swaps two space-separated words.
swapWords('hello world') // β 'world hello'