This is a non-optimized version involving lots of recursion, rather please check the
`Specifying a function as a parameter` section in
(MDN)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace]