Also tried the standard for loop approach which actually proved easier to deal with than every:
for
every
const isValid = function(s) { const pairs = { '(': ')', '[': ']', '{': '}' }; const openParens = []; for (let i = 0; i < s.length; i++) { const endParen = pairs[s[i]]; if (endParen) openParens.push(endParen); else if (openParens[openParens.length - 1] === s[i]) openParens.pop(); else return false; } return openParens.length ? false : true; };
Awesome work man ! keep up !
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Also tried the standard
forloop approach which actually proved easier to deal with thanevery:Awesome work man ! keep up !