Quantcast
Channel: User Yay295 - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 12

Answer by Yay295 for Count of "a"s and "b"s must be equal. Did you get it computer?

$
0
0

JavaScript, 34 bytes

s=>(s=s.match`^a(.*)b$`[1])?f(s):1

In true automata fashion, this function returns 1 if it's true, and fails if it's not.

f=s=>(s=s.match`^a(.*)b$`[1])?f(s):1let test_strings = ["ab", "aabb", "", "a", "abb", "abc", "abab", "abba"];test_strings.map(s => {try {console.log("f(\""+ s +"\") returned "+ f(s));}catch(e) {console.log("f(\""+ s +"\") threw "+ e);}});

Viewing all articles
Browse latest Browse all 12

Trending Articles