To convey the merits of Lambda Calculus, and even JavaScript's ability to implement such (Turing-complete) formulas, I'd like to see the most elegant and concise way that one JS file could print the correct string of the following language, given a natural number n (zero-based):
anbncn
This would also mean without the use of external libraries, nor iterative machinery (e.g. "while", "for", etc.).
anbn , for example, being a context-free grammar perhaps can get no simpler than:
function print(n) {if(n>0) {console.log('a'); print(n--); console.log('b');}}
Since you're OK with recursion in your example,
If that's not as appealing, you could roll the three printX functions together in a manner like this:
Give or take some off-by-ones with
<
vs<=
.