I was feeling a little bummed out when I wrote my own palindrome function and after testing that it worked I decided to see how other people approached writing this function.
Although the exercise suggested reading about String.prototype.replace(), I was unable to make heads or tails from the MDN documentation. I didn’t understand what I was supposed to do with the 2nd parameter newSubstr as shown below.
So basically, I wanted any character that my regexp matched to be a part of my newSubstr, but the documentation made no sense to me and I abandoned using str.replace in favor of String.prototype.match()
Still feel bummed by the girth of my function code compared to other’s refactored code in this thread. I wanted to test the performance of our functions and discovered using jsperf. To my amazement, the code I wrote turned out to be the faster of the other approaches which helped eased the way I felt about my code.
I do not know how long jsperf keeps the test cases around, but here is a link https://jsperf.com/kerry-ruddock1 for those interested in running the test and checking the results