arr = [1, 3, 7, 9, 11];
function max(arr) {
var maxval = arr[0];
var i = 0;
while (arr[i] != undefined) {
if (maxval < arr[i+1]) {
maxval = arr[i+1];
}
i++;
}
return maxval;
}
document.write(max(arr));
11
arr = [1, 3, 7, 9, 11];
function min(arr) {
var minval = arr[0];
var i = 0;
while (arr[i] != undefined) {
if (minval > arr[i+1]) {
minval = arr[i+1];
}
i++;
}
return minval;
}
document.write(min(arr));
1
No comments:
Post a Comment