Skip to content

Instantly share code, notes, and snippets.

@jacobp100
Created November 1, 2019 20:03
Show Gist options
  • Save jacobp100/9d9dc08de3b4352b168a5bfa139794a4 to your computer and use it in GitHub Desktop.
Save jacobp100/9d9dc08de3b4352b168a5bfa139794a4 to your computer and use it in GitHub Desktop.
let firstBracketPair = inputChars => {
let rec iter = (currentState, chars, currentIndex) =>
switch (currentState, chars) {
| (`FoundBracket(startIndex), [')', ..._]) =>
Some((startIndex, currentIndex))
| (_, ['(', ...tail]) =>
iter(`FoundBracket(currentIndex), tail, currentIndex + 1)
| (_, [_, ...tail]) =>
iter(currentState, tail, currentIndex + 1)
| (_, []) =>
None
};
inputChars(`NoBrackets, inputChars, 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment