JavaScript/Line reverser

To reverse the lines of a string, one needs to verify whether the data that was fed into the function is a string. This is done using the  function. If the data is a number, it will be returned without being processed, since pure numbers can only be in one line.

Then, the length of the first line is detected, so the line can be extracted from the input string using the  function, and appended to the variable that will be returned after being built.

After the first line of the input string is appended to the output variable, the first line and the first line break will be cut off from the input string. This process is repeated until there are no more lines left in the input string.

The last input and output are memorized in the  and   variables respectively, so they can be re-used without having to run the line reverser function again.

Try it out
You can test the code by first loading it by pasting it into the console of the web development tools on a desktop computer or laptop web browser, or into the URL bar of a mobile web browser after.

After having loaded the script, enter  in the URL bar or the web development tools. is a line feed. The lines will be returned reversedly.