function highest(){
return makeArray(arguments).sort(function(a,b){
return b - a;
});
}
function makeArray(array){
return Array().slice.call( array );
}
assert(highest(1, 1, 2, 3)[0] == 3, "Get the highest value.");
assert(highest(3, 1, 2, 3, 4, 5)[1] == 4, "Verify the results.");
Now, why does Array()
even return something meaningful, without a new
operator? Most "class" definitions I've seen in JS return undefined
if called without new
:
function User(name) {
this.name = name;
this.jump = function() {
console.log(name + " is jumping!");
}
}
assert(typeof(User("no New")) == 'undefined');