“Rata -rata array” Kode Jawaban

cara menghitung rata -rata array dalam javascript

const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length
TechWhizKid

rata -rata array js

const avg = arr => {
  const sum = arr.reduce((acc, cur) => acc + cur);
  const average = sum/arr.length;
  return average;
}

console.log(avg([1, 2, 3, 7, 8]));
Unusual Unicorn

Mendapatkan rata -rata javascript array

var total = 0;
for(var i = 0; i < grades.length; i++) {
    total += grades[i];
}
var avg = total / grades.length;
Stupid Stoat

JavaScript menghitung rata -rata array

const sum = times.reduce((a, b) => a + b, 0);
const avg = (sum / times.length) || 0;

console.log(`The sum is: ${sum}. The average is: ${avg}.`);
Scary Serval

Rata -rata array num di javascript?

class Avg {
    constructor() {}

    static average(array) {
        var total = 0;
        var count = 0;

        jQuery.each(array, function(index, value) {
            total += value;
            count++;
        });

        return total / count;
    }
}

var arry = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
console.log(Avg.average(arry));
Repulsive Raven

Rata -rata array

public class ArrayAverage {
    public static void main(String[] args) {
        double[] numbers = new double[5]; //double[] arr = {6.7, 8.9, 2.7, 6, 1};
        numbers[0] = 6.7;
        numbers[1] = 8.9;
        numbers[2] = 2.7;
        numbers[3] = 6;
        numbers[4] = 1;

        double sum = 0;

        for (int i = 0; i < numbers.length; i++) {
            sum = sum + numbers[i];
        }
        System.out.println(sum);
    }
}
Breakable Boar

Jawaban yang mirip dengan “Rata -rata array”

Pertanyaan yang mirip dengan “Rata -rata array”

Lebih banyak jawaban terkait untuk “Rata -rata array” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya