Skip to content

Instantly share code, notes, and snippets.

@andrew8088
Last active April 20, 2021 15:47
Show Gist options
  • Save andrew8088/1aaa9c453176c916cf22ebc7e8524021 to your computer and use it in GitHub Desktop.
Save andrew8088/1aaa9c453176c916cf22ebc7e8524021 to your computer and use it in GitHub Desktop.
isProperlyNested interview question
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
);
}
@andrew8088
Copy link
Author

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, and false 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment