Create a function in JavaScript called "sum" that takes in an array as a parameter and returns the sum of all of the EVEN numbers in a given array. Please note: the array passed in can have any data type, i.e. Strings, Numbers, Booleans, undefined, etc.
HINT: the expression typeof will help discern var types. For example if I have: var x = 4, and I do typeof(x) - the output would be "Number"
Example run:
sum([1, 4, 8, 10, 'q', true]) //output would be 22
sum([3 , 5, 7, true, false, 'po']) //output would be 0
==================== Start Program ====================
<!DOCTYPE html>
<html>
<body>
<script>
myArray = [1, 4, 8, 10, 'q', true]; //array to accept input
//myArray = [3 , 5, 7, true, false, 'po'];
var total = 0; //adding elements one by one
var result = sum(myArray); //calling sum function with array as
parameter
document.write("Sum of Even Numbers: "+result); //printing the result
function sum(myArray) { //sum function
for(var i=0;i<myArray.length;i++){
if(typeof myArray[i] === 'number'){ //checking for
number data type
if(myArray[i]%2==0){ //checking for even numbers
total = total + myArray[i]; //adding even
numbers
}
}
}
return total; //returning result to function call
}
</script>
</body>
</html>
==================== End Program ====================
Output: Sum of Even Numbers: 22
Create a function in JavaScript called "sum" that takes in an array as a parameter and...
Javascript function that takes an array parameter and returns an array value. The assumption is that the array is an integer array. The returned array should be composed of the square of the elements in the array parameter for the corresponding position.
JavaScript Write a function named "sort_by_length" that takes a list/array of strings as a parameter and sorts the strings by their length
create a javascript function named bbqFood that takes in an object and returns an array. The input object will have strings naming party foods as the key and the numbers of people that each key will feed as its values. return an array containing all of the keys whose values are greater than 10, menaing it will feed more than 10 people. example bbqfood(['taco':15, 'hamburger':6,'pasta':42,'fruit':23}) must return ['taco','pasta','fruit']
in JavaScript - Create a function titled "counter" that takes an array of numbers as the parameter. The function is then to return an array holding the numbers of negative elements, zeros, and values greater than zero in the given array parameter.
create a javascript function named sumBeyond that takes in an array of numbers and returns the summation of the values in the array that are greater than (but not including) 42. If there are no values greater than 42, the function should return 0. example- sumBeyond([2,85,932,0,7,-5,0,32]) must return 1017
Define a JavaScript function named activityScore with one parameter. Assume the function will be called with an array of Numbers. Define the function so that it creates an Object. This object should have a key equal to "score", and its paired value should be set to the sum of the array’s entries. Return the JSON blob encoding the Object.
Write a function that takes an array of C-strings as a parameter and the number of elements currently stored in the array, and returns a single C-string pointer that is the concatenation of all C-strings in the array. Note: The function must take 2 parameters and return "char *". Any other ways will cause some deduction of points.
Write a function named "find_key" that takes a key-value store as a parameter with strings as keys and integers as values. The function returns a boolean representing true if the string "focus" is in the input as a key, false otherwise(javascript)
More Practice: Writing Lists& Strings . Write a function average_ evens that takes a list of numbers as parameters, and adds all the even numbers together and returns their average using a list Example function call: print (average_evens (I-2, -3, 4, 0, 1, 2,3 Outputs: 0 Write a function match that takes two strings as a parameter and returns how many letters the strings have in common. You should treat upper and lower case letters as the same letter ('A,...
Write a method called averageVowels that takes an ArrayList of strings as a parameter and returns the average number of vowel characters (a, e, i, o, u) in all Strings in the list. If your method is passed an empty ArrayList, it should return 0.0.