1) Why does the function smallest fail? I think it conforms to the example in the Mozilla documentation https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/min, which says
function getMin(x,y) { //from Mozilla documentation
return Math.min(x,y)
}
function smallest(array){ //my own experimentation with Resig`s example
return Math.min(array);
}
function largest(array){ //from John Resig`s learning advanced JavaScript #41
return Math.max.apply( Math, array );
}
assert(smallest([0, 1, 2, 3]) == 0, "Locate the smallest value.");
assert(largest([0, 1, 2, 3]) == 3, "Locate the largest value.");
Math.minandMath.maxtakes any number of numbers, as arguments. Yoursmallestis trying to pass an array, not numbers.The use of
apply(as inlargestin your example) pastes the elements of the array as arguments.