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.
function sayHello(arr) //function taking array as parameter and
returning array result
{result=[];//array to store result
//calculating square of each element and storing in the result
array
for (i=0; i<arr.length; i++){
sqr=Math.pow(arr[i],2);
result.push(sqr);
}
return result; //returning result array
}
var x = [1,2,3]; //intializing x array
var y=sayHello(x); //calling function and passing array x
//printing resulting array in alert
for (i=0; i<y.length; i++){
alert(y[i]);
}
//Please let me know in case of any doubt,Thanks.
Javascript function that takes an array parameter and returns an array value. The assumption is that...
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
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 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,...
In Javascript: Write a function named "categorize" that takes a string as a parameter and returns "short" if the input has less than 6 characters, "medium" if the input has greater than or equal to 6 but less than 7, and returns "long" if the input has greater than or equal to 7 characters. Thanks
in javascript Write a function named "sort_by_average_rating" that takes a list/array of key-value stores as a parameter where each key-value store has keys "ratings", "budget", and "box_office" where budget and box_office are integers and ratings is a list of integers. Sort the input based on the average of the values in "ratings"
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.
javascript-Write a function named "json_average" that takes a JSON formatted string as a parameter in the format of an array of objects where each object has keys "mass", "density", "temperature", and "velocity" and each key maps to a floating point number. This function should return the average "velocity" of all the objects in the array as a JSON string in the format {"velocity": }
Given an array and a starting position write a function replaceFromN, that takes an integer array 'array', the size of the array size and a starting positions 'n' as parameters and replaces the elements starting from that index onward with the sequence 1,2,3,... The function returns nothing. void replaceFromN(int array[], int size, int n) For example, given array= {15,12,4,9,2,3} n =2 the function should modify array to be {15,12,1,2,3,4}
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']