Created
May 28, 2022 19:07
-
-
Save fersilva16/4c408f0e72f7f820bffd76ddb128a4a5 to your computer and use it in GitHub Desktop.
a*b parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
/** | |
* @param {string} str | |
*/ | |
const asb = ([head, ...tail]) => { | |
if (head === 'a') return asb(tail); | |
if (head === 'b' && !tail.length) return true; | |
return false; | |
}; | |
assert(asb('b') === true); | |
assert(asb('ab') === true); | |
assert(asb('aab') === true); | |
assert(asb('aaab') === true); | |
assert(asb('aaaab') === true); | |
assert(asb('aaaaab') === true); | |
assert(asb('a') === false); | |
assert(asb('c') === false); | |
assert(asb('ba') === false); | |
assert(asb('bb') === false); | |
assert(asb('bc') === false); | |
assert(asb('cb') === false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment