James Cat's rough && ready blog

The first recursive function I’ve ever really understood.

Posted in Uncategorized by zzjames on March 1, 2016

In JavaScript

var printDots = function(n) {
    if(n===0) {                     // terminating condition
        return "";                  // terminating value
    } else {
        return "."+printDots(n-1);  // method of construction
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: