Answer to the Ultimate Question

by conzett

HTML

<p>Input is: [7, 13, 42, 69] See console for output.</p>

JavaScript

function meaningOfLife(i) {
    if (i.length > 0 && i[0] !== 42) {
        var v = i.shift(); //pull off the first array element
        console.log(v); //log it to the console
        meaningOfLife(i); //call the function again
        i.unshift(v); //pop the array element back on
        return v; //for testing
    }
}

var input = [7, 13, 42, 69];
meaningOfLife(input);