Timeline for Easy to read palindrome checker
Current License: CC BY-SA 4.0
        17 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 31, 2019 at 17:36 | comment | added | DreamVision2017 | @Feathercrown I agree | |
| Mar 31, 2019 at 17:31 | vote | accept | DreamVision2017 | ||
| Mar 31, 2019 at 5:14 | comment | added | Feathercrown | Of course, the goal is to get an "easy to read" palindrome checker. Frankly, I doubt that the improvements to the efficiency of the method, impressive though they are, outweigh the looming disaster that would be maintaining or reading them. | |
| Mar 31, 2019 at 2:02 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    add two pointers version 
                
             
        
     | 
| Mar 31, 2019 at 0:44 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    add optimization note 
                
             
        
     | 
| Mar 31, 2019 at 0:29 | comment | added | ggorlen | @cbojar On the flip side, doing the sub first reduces the number of characters needed to lowercase. I'm not sure how the regex engine works, but I imagine on this one, it should be a one-pass job since there are no quantifiers (I may be mistaken). Either way, like you say, a more performance-conscious implementation would likely avoid all of these functions (I'm sure this can be done in one pass with two pointers), but I think the OP's code needs work before the micro-performance tweaks are worth looking at. | |
| Mar 31, 2019 at 0:17 | comment | added | ggorlen | 
        
            
    @Feathercrown ==/=== doesn't work on arrays, unfortunately, but good thought.
        
     | 
|
| Mar 31, 2019 at 0:06 | comment | added | cbojar | Small optimization for your rewrite, lowercase the string first and avoid the additional cost of a case-insensitive regex. There are larger optimizations that could also be done, but that make the code more complicated. | |
| Mar 31, 2019 at 0:04 | comment | added | Feathercrown | 
        
            
    This is pretty much exactly what I was thinking as I read it. It's weird just how much more compressed everything gets.... Anyways, wouldn't it be better to add a .split() to the first line so the last could be simply return str === str.reverse();?
        
     | 
|
| Mar 30, 2019 at 21:48 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    clarify first time complexity point 
                
             
        
     | 
| Mar 30, 2019 at 21:30 | comment | added | ggorlen | 
        
            
    Your code makes ~11 trips over the n-sized input, which is why I mention the high constant factor. If you do the replacement and lowercasing one time, you can get away with about 6 trips through the input. I count any array function, loop or === as one trip over the input. This is a pretty minor concern relative to the other points, though, and addressing the style points accidentally improves your performance along the way.
        
     | 
|
| Mar 30, 2019 at 21:20 | comment | added | DreamVision2017 | Good points, just to make sure is the time complexity O(n) because the reverse function traverses through each element of the array? | |
| Mar 30, 2019 at 21:06 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    shorten and simplify 
                
             
        
     | 
| Mar 30, 2019 at 21:00 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    shorten and simplify 
                
             
        
     | 
| Mar 30, 2019 at 20:45 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    clarify answer 
                
             
        
     | 
| Mar 30, 2019 at 20:35 | history | edited | ggorlen | CC BY-SA 4.0 | 
        
            
             
                
                    add titles and improve explanation 
                
             
        
     | 
| Mar 30, 2019 at 20:22 | history | answered | ggorlen | CC BY-SA 4.0 |