timoxley / functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
2.06k stars 441 forks source link

Item 2 passes w/o any operations being performed. #186

Open switheyw opened 7 years ago

switheyw commented 7 years ago

The first function below, does not make any calls to operation(), but is still seen as correct. This is so even though only dashes were logged to console.

function repeat(operation, num) {
   if ( num == 0 )
      return
   repeat(operation, num - 1);
}

The solution as supplied:

function repeat(operation, num) {
      if (num <= 0) return
      operation()
      return repeat(operation, --num)
    }