modify your code to run in the IDE's Node.js environment. The output of your program running in
Question:
modify your code to run in the IDE's Node.js environment. The output of your program running in the Node.js environment should be similar to Figure 1 (i.e. individually list each element of the given array). An added requirement is to sum up the values of the array elements and output that as well. Test your code with the following array: [8, 22, 40, 12, 2]. Created By:)
function arrayAverage(anArray){
var sum = 0;
for (i=0; i
}
return sum/anArray.length;
}
function arrayLargest(anArray){
var large = anArray[0];
for(var i = 0; i < anArray.length; i++) {
if(anArray[i] > large) {
large = anArray[i];
}
}
return large;
}
function isEven(anArray) {
for(var i = 0; i < anArray.length; i++) {
if(anArray[i] % 2 == 0) {
return true;
}
}
return false;
}
function isAllEven(anArray) {
var count = 0;
for(var i = 0; i < anArray.length; i++) {
if(anArray[i]%2 == 0) {
count++;
}
}
if(count == anArray.length) {
return true;
}
else {
return false;
}
}
function isContained(anArray, aString) {
for(i = 0; i < anArray.length; i++) {
for(var i=0;i
return true;
}
return false}
}
function performTasks() {
document.write("Awesome Array Functions!
");
document.write("");
");
document.write("
document.write("The arrayAverage function accepts an array of numbers as an argument and returns their average. So, the average of array [8, 30, 12, 10] is: ");
document.write("");
document.write(arrayAverage([8, 30, 12, 10]));
document.write("");
document.write("
document.write("
document.write("The arrayLargest function accepts an array of numbers as an argument and returns its largest number. So, the largest item in array [3, 14, 9] is: ");
document.write("");
document.write(arrayLargest([3,14,9]));
document.write("");
document.write("
document.write("
document.write("The isEven function accepts an array of numbers and returns true if it contains at least one even number, false otherwise. So, does the array [99, 65, 33, 24] contain an even number? ");
document.write("");
document.write(isEven([99, 65, 33, 24]));
document.write("");
document.write("
How about array[57, 43, 21]? " + isEven([57, 43, 21]));
document.write("
document.write("
document.write("The isAllEven function accepts an array of numbers and returns true if every number is even, false otherwise. So, is the array [12, 14, 5, 18] all even? ");
document.write("");
document.write(isAllEven([12, 14, 5, 18]));
document.write("");
document.write("
How about array[22, 34, 46]? " + isEven([22, 34, 46]));
document.write("
document.write("
document.write("The isContained function accepts two arguments, 'an array of strings' and a 'string', and returns true if the 'string' is contained in the array, false otherwise. So, is '2020' contained in the array ['CIS', '425', 'Web Development', '2020']? ");
document.write("");
document.write(isContained(["CIS", "425", "Web Development", "2020"], "2020"));
document.write("");
document.write("
How about '2019' in the array ['CIS', '425', 'Web Development', '2020']? " + isContained(["CIS", "425", "Web Development", "2020"], "2019"));
document.write("
document.write("
document.write("