DEV Community

Discussion on: Valid parentheses, solving a Facebook interview question.

Collapse
 
namhle profile image
Nam Hoang Le • Edited

You can check a number is not equal to zero by if (n) {} or check empty string by if (!s) ....
Of course, just use object literal for you map. :)

The last statement should be return !stack.length.

Bonus point: we can solve it shorter by using recursion and String replace method.

Collapse
 
akhilpokle profile image
Akhil

I wrote this way for code readability :)

Collapse
 
namhle profile image
Nam Hoang Le • Edited

Yes, that way is better for products. But the boundary between readability and cleaning is not always clear. :)

Thread Thread
 
akhilpokle profile image
Akhil

True that.