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.
The second argument can be a function. It receives the matched substring and returns the replacement.
Challenge: Implement doubleNumbers(str) that doubles every digit found in the string.
doubleNumbers('a1b2') // β 'a2b4'