question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect text for test cases in Balanced Brackets question

See original GitHub issue

Many of the test cases on the balanced brackets challenge state incorrect expectations. For example isBalanced("][")should return true.. There are many similar test cases like this.

The tests themselves seem to be correct despite the html text. It is worth noting however, that the test cases are missing at least one case that should be added. Please consider adding isBalanced("[]]]")should return false.

This case covers instances where:

  1. A stack approach is used to solve the problem.
  2. The programmer checks for an even number of characters before iterating.
  3. The programmer does not check for an empty stack before calling .pop()

Example student code where the current tests pass but this case would fail:

function isBalanced(str) {
    let matched = [];
    if (str.length == 0) {
        return true;
    } else if (str.length % 2 != 0) {
        return false;
    } else {
        for (let i = 0; i < str.length; i++) {
            if (str[i] == "[") {
                matched.push(str[i]);
            } else {
                matched.pop();
            }
        }
        if (matched.length !== 0) {
            return false;
        }
        return true;
    }
}

Page with problem: https://learn.freecodecamp.org/coding-interview-prep/rosetta-code/balanced-brackets/

Tell us about your browser and operating system:

  • Browser Name: Chrome
  • Browser Version: 76.0.3809.100 (Official Build) (64-bit)
  • Operating System: MacOS 10.13.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
moT01commented, Sep 16, 2019

the ninth from the top… isBalanced("[[][]]][") should return true. - removing the last [ should catch the cases he is referring to - so it would become isBalanced("[[][]]]") should return false.

0reactions
RandellDawsoncommented, Sep 15, 2019

I think we should change one of the existing tests instead of adding another one… and maybe even remove several of them, since there are 19 tests on this challenge.

@James-Crean Would you want to suggest a change for one of the tests?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Check for Balanced Brackets in an expression (well ...
Given an expression string, write a program to examine whether the pairs and the orders of parentheses are balanced in expression or not....
Read more >
Testing if Parenthesis are balanced, (a{[]b({})}c)[] returns false ...
From looking at the code, I think the problem is that your IsBalanced method returns false right away as soon as it runs...
Read more >
Balanced Brackets Algorithm in Java - Baeldung
There are a couple of special cases to keep in mind: null is considered to be unbalanced, while the empty string is considered...
Read more >
Valid Parentheses - LeetCode
Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. Example 1:...
Read more >
The valid parentheses problem - Educative.io
In case of a closing bracket, check if the stack is empty. If not, pop in a closing parenthesis if the top of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found