How to Determine the Minimum, Maximum, Average, Odd Numbers and Even Numbers

Hello everyone, by the way, I want to share the results of my answers related to discussions in the CodeSaya.com forum. It feels incomplete if I do not share on this blog as writing, which of course I think can be useful for blog visitors

By the way, did you all know? What is CodeSaya.com?

CodeSaya.com is the Indonesian language online learning media that provides various kinds of programming classes such as Python, JavaScript, PHP and also Version Control (GIT).

Some time ago, I had time to write answers related to discussion questions with cases like this:

Mau nanya nih saya kan punya kasus diberikan sebuah function numberProcessing(numberArr) yang menerima satu parameter berupa array yang berisikan angka. Tentukan nilai minimum, maksimum, rata-rata (genapkan ke bilangan terdekat), bilangan ganjil dan bilangan genap. klo method saya ngerti tinggal math.min, math.max tapi ini pake loop .

function numberProcessing(numberArr) {
}

console.log(numberProcessing([1, 3, 5, 1, 2, 8, 10, 0, 3]));
// “Min: 0, Max: 10, Mean: 4, Odds: 1-3-5-1-3, Evens: 2-8-10-0”

Here I am trying to help with a simple code and of course with my version:

<script>
    var TempMin = TempMax = TempMean = TempOdds = TempEvens = Content = '';

    function numberProcessing(myNumber){
        var j =0;
        for(var i=0; i<myNumber.length;i++){

            if(j == 0){
                TempMin = myNumber[i];
                TempMax = myNumber[i];
                TempMean = 0;
            }

            // CHECK MIN
            if(myNumber[i] < TempMin){
                TempMin = myNumber[i];
            }

            // CHECK MAX
            if(myNumber[i] > TempMax){
                TempMax = myNumber[i];
            }

            // CHECK AVERAGE
            TempMean += myNumber[i];
            var Mean = parseInt(TempMean / myNumber.length);
            if(Mean % 2 == 1){
                Mean += 1;
            }

            // CHECK ODD && EVEN
            if(myNumber[i] % 2 == 1){
                TempOdds += (TempOdds != '' ? '-' + myNumber[i] : myNumber[i]);
            } else {
                TempEvens += (TempEvens != '' ? '-' + myNumber[i] : myNumber[i]);
            }

            j++;
        }

        Content = 'Min: ' + TempMin + 
                ', Max: ' + TempMax + 
                ', Mean: ' + Mean + 
                ', Odds: ' + TempOdds + 
                ', Evens: ' + TempEvens;

        return Content;
    }

    console.log(numberProcessing([1, 3, 5, 1, 2, 8, 10, 0, 3]));
</script>

If you have another simpler way to write the program code, you can share it via the comments below. See You, Happy Blogging!