We need you to write a C# method - the class doesn't matter - that has this signature:
public bool IsBalanced(string value)
{
// implementation goes here
}Given a string value, the method must return true or false depending on whether the brackets balance.
Brackets are these 6 characters: () {} [] and by "balanced" we mean "correctly closed". Think of a parameterised method call: the opening paranthesis ( must have a matching closing character ); any interpolated brackets must be closed off before the "outer" brackets are closed.
True:
- ( )
- { } { }
- [ { ( ) } ]
- [ ( ) ( ) ]
- [()(())]
False:
- {
- }
- } }
- { } {
- [ { ( } ) ]
Ignore them: they don't count towards bracket balancing. If value doesn't have any bracket characters, just return true.
We're hot on test driven development, in the pure style, and that means test first and test often. Remember your early tutorials on TDD? That's what we practice.
That means no ChatGPT nor Github Copilot!
You'll be sharing your screen with someone else, and they will be assessing everything.
As you go through the kata, don't isolate yourself. Talk, and talk a lot: we want to hear your thinking.
So if you've got a problem in year head, talk out loud (don't worry, we do not record!)
If you need to pause to collect your thoughts, please just say so.
-
Can you factor the code for elegance and readability?
-
How would you test with the minimum number of tests and test cases?
-
What is the best way to verify your tests are correct?
-
Speed! What are the bottlenecks?
Many thanks to @robcthegeek