Upload files to "arrays"
This commit is contained in:
32
arrays/Example4.js
Normal file
32
arrays/Example4.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// METHODS OF ARRAYS
|
||||
/*
|
||||
push(elem_list): Adds one or more elements to the end of the array,
|
||||
and returns the new length of the array.
|
||||
*/
|
||||
let getSum = function(list)
|
||||
{
|
||||
let sum=0
|
||||
for(let i in list)
|
||||
{
|
||||
let n = list[i]
|
||||
sum = sum + n
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
let getAverage = function(list)
|
||||
{
|
||||
let sum = getSum(list);
|
||||
let ave = sum/list.length
|
||||
return ave
|
||||
}
|
||||
|
||||
let numbers = [2, 6, 4, 7, 3, 6]
|
||||
console.log("Array: " +numbers)
|
||||
let sum = getSum(numbers)
|
||||
let average = getAverage(numbers)
|
||||
|
||||
console.log("Sum = " +sum )
|
||||
console.log("Average = " +average)
|
||||
|
||||
Reference in New Issue
Block a user