Answer to the Ultimate Question Tests
by conzett
HTML
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
<h1 id="qunit-header">Answer to the Ultimate Question Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
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
}
}
$(document).ready(function() {
test("array value at index with value of '42' returns undefined", function() {
var value = meaningOfLife([42]);
equals(value, undefined, "We expect value to be undefined");
});
test("array value at index with a value not '42' returns that value", function() {
var value = meaningOfLife([13]);
equals(value, 13, "We expect value to be 13");
});
test("an empty array returns undefined", function() {
var value = meaningOfLife([]);
equals(value, undefined, "We expect value to be undefined");
});
});