Below, you can find another hint for the Challenge.
You should only get here after reading, digesting, and applying the .
So, the aim is to solve two more problems:
Let us address the second problem first (divide and conquer; separation of concerns). This means that we are looking for a way to have the program write itself as output, where each statement is on a separate line, but where the string literal is still long and on a single line.
The newlines will not appear using write(), because we have no way of putting newlines in the string literal.
N.B. JavaScript does have a facility to put newlines in string literals (we could use NL or the escape mechanism '\n'). But we want to avoid that, because
- it requires the use of advanced features of the programming language;
- it would introduce new complications (which, admittedly, can be overcome);
- it is not necessary;
- it is more instructive to avoid that.
Consequently, the newlines will only appear when we use writeln() instead of write().
There is a blunt way of approaching this problem. Write each program line by extracting it from S using a statement of the form:
where you put appropriate numbers (start index and length) on the dots.
Can you develop this idea into a better solution?
Try your program in the machine, and see if you can extend it to a complete solution.
It is your turn ...
If you tried this hint, or do not see how it helps, then you are ready for the .