← Back to challenges

Clear Brackets

JavaScriptHardstringslogicvalidation

Instructions

Create a function brackets() that takes a string and checks that the brackets in the math expression are correct. The function should return true or false.

Examples

brackets("(a*(b-c)..... )") ➞ true

brackets(")(a-b-45/7*(a-34))") ➞ false

brackets("sin(90...)+.............cos1)") ➞ false

Notes

  • The string may not contain brackets, then return true.
  • String may contain spaces.
  • The string may be empty.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.