First of all, the second example return false. Go on, run it, look for the mistake, I'll wait here. Here's some lorem ipsum to force a context switch in your brain:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla diam id tortor vestibulum, a imperdiet mauris lacinia. Sed egestas eros eros, quis eleifend lectus pharetra sit amet. Nullam fringilla finibus velit non euismod. Donec iaculis cursus sapien, quis vestibulum ante interdum vitae. Sed scelerisque scelerisque accumsan. Donec sed orci nisl. Mauris eget aliquet orci. Integer consectetur rhoncus tristique. Aenean quis sodales mauris. Donec fringilla lacus commodo pulvinar euismod. Sed at laoreet dui. Nam consequat vitae ante ut efficitur. Sed vel metus at dui elementum aliquam. Sed et odio sed sem facilisis tristique.
Still here? Good. I hope you noticed all by yourself that you first remove all non-lowercase letters and then convert the input to lowercase. Thus you remove the uppercase 'C' in the very first step.
This is kind of the same mistake: it doesn't work for non-latin characters. Is saös a palindrome? Certainly not! However, after deleting the non-latin letter, it suddenly is, causing a false positive.
In case you now got the insane idea to list all printable characters and are about to write something like replace(/[^A-Za-zäöüÄÖÜßłŧøþæſðđŋħĸłΩŁŦ¥ıØÞÆẞÐŊĦŁ]+/g,"") or something like that, here's a better idea: first convert to lowercase, then filter out all whitespace. And just in case you get the idea to write .toLowerCase().replace(/[ \t\r\n]/g,"") (which obviously leaves out the less common whitespace things like zwnbsp or half-space), use the character group instead of trying to reinvent a broken wheel. In short, the following works: .toLowerCase().replace(/\s/g, "") (At least it works much better.)
3.2 uses a stack for the sake of using a stack. Instead, one could just keep a counter of currently open parenthesis: increase if a ( is encountered, and decrease if a ) is encountered. If at any point in time the counter becomes negative, it's invalid. If the counter is non-zero in the end, it's invalid. In all other cases, it's valid.
5.1 is recursive for the sake of being recursive. This introduced a subtle error that now is hard to fix: decimalToBinary(0) returns "0"
And finally:
"A mostly reasonable" -> in what regard "reasonable"? None of these questions prove any knowledge about JS. In fact, you could ask them in any other question as well. How about more javascript-y questions like "Where and how can you include a script into a web page? When and why do you choose each method?" or "How do you efficiently detect whether some animated element is no longer visible and start/stop the animation appropriately?" or something like that.
"collection" -> from where did you scrape these? Google knows a lot more and a lot better questions.
"of technical software development interview questions" -> says who? Source? Just imagine you're a manager of a team. You want to write the next GitHub or whatever. Would you be comfortable employing someone who only proved that yes, they know how to sort an array? Also, what's the point of using a built-in function? Do you just want to test whether they have memorized the entire documentation and know everything by heart? What for?
saös
a palindrome? Certainly not! However, after deleting the non-latin letter, it suddenly is, causing a false positive.replace(/[^A-Za-zäöüÄÖÜßłŧøþæſðđŋħĸłΩŁŦ¥ıØÞÆẞÐŊĦŁ]+/g,"")
or something like that, here's a better idea: first convert to lowercase, then filter out all whitespace. And just in case you get the idea to write.toLowerCase().replace(/[ \t\r\n]/g,"")
(which obviously leaves out the less common whitespace things like zwnbsp or half-space), use the character group instead of trying to reinvent a broken wheel. In short, the following works:.toLowerCase().replace(/\s/g, "")
(At least it works much better.)(
is encountered, and decrease if a)
is encountered. If at any point in time the counter becomes negative, it's invalid. If the counter is non-zero in the end, it's invalid. In all other cases, it's valid.decimalToBinary(0)
returns"0"
And finally: