Here is the code:
function repeat(operation, num) { return function() { if (num <= 0) return operation() return repeat(operation, --num) }
The while loop will keep running until the condition is falsy.
while
fn && typeof fn === 'function' will be falsy either if fn itself is falsy, or if fn is anything other than a function.
fn && typeof fn === 'function'
fn
The first half is actually redundant, since falsy values are also not functions.