November 20, 2017
As a coder or a apiring one you have probably experienced many moments where all the smokes blows away and you understand something much clearer. One of these moments for me was when I was introduced to recoursion. Probably, while learning Scheme or Haskell. The basic idea is that a function calls itself. Don’t use recoursion when you write definitions, because circularity is BAD philosophy.
Here is a very simple example that loops over an array, and prints the result, without using a regular loop; like while, for, do, map, forEach etc.
You could of course do the same with a for of for example:
To figure out how to do something, without using the “default” is always a very good exercise. The basic idea above is to print the first element, and re-run the function if, the input is larger than one with the array minus the first element as input.