New answers tagged

2

This is even more stale now, but I thought I would chuck this in there. Once you have cleaned the string, you only need to do half a loop to test if it is a palindrome. PALINDROME_PATTERN = /[^a-z]/g function testPalindrome(s) { if (typeof s !== 'string') throw 'Parameter is not a string!' const s2 = s.toLowerCase().replace(PALINDROME_PATTERN, '') for ...


0

I see the performance tag added to this post. Did you intent to have answers address performance in terms of time, space or other aspects? If you are looking to optimize performance in terms of time then I must restrain myself from suggesting changing the outer for loop to a for of loop. However I do see there is a forEach loop inside the nested for loop. If ...


1

Variable declaration keywords One thing I notice is that the var keyword is used in some functions while others use const. The variables dbo, MongoClient and url are never reassigned so const can be used for those. Using const when re-assignment isn't needed is a good habit because it can help avoid accidental re-assignment and other bugs. Many users also ...


Top 50 recent answers are included