Last active
April 20, 2021 15:47
-
-
Save andrew8088/1aaa9c453176c916cf22ebc7e8524021 to your computer and use it in GitHub Desktop.
isProperlyNested interview question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isProperlyNested(input) { | |
} | |
test("{}", true); | |
test("(()", false); | |
test("()[]", true); | |
test("(([{]))", false); | |
test("[(())]{}()", true); | |
test("[(()){}()", false); | |
function test(input, expected) { | |
const output = isProperlyNested(input); | |
const state = output === expected ? "PASS" : "FAIL"; | |
console.log( | |
state + ': isProperlyNested("' + input + '") should equal ' + expected | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An interview programming question: the
isProperlyNested
function should take a string input and return a boolean:true
if the brackets/braces/parenthesis in the string are properly nested, andfalse
if they are not. You can expect the string input to only input the opening and closing characters ({ } [ ] ( )
), and no others (that is, no need to clean the string).