0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【js】配列の中の数字の平均値と最大値

Posted at

var scores = [72, 93, 85, 68];
console.log('scores: ' + scores);

// この下にコードを書いてください
var ave = function(arr){
var sum = 0;
for (var i = 0; i < arr.length; i++) {
sum +=arr[i];
}
return sum/arr.length;
}

console.log('平均点は'+ave(scores)+'点です。');

var max = function(arr){
var maxval = 0;
for (var j = 0; j < arr.length; j++) {
if (maxval < arr[j]) {
maxval = arr[j];
}
}
return maxval;
}
console.log('最高点は'+max(scores)+'点です');

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?