Write a function called
addNeighbors that takes an array of numbers and adds each number in
the array to the number next to it. The array will always have an
even number of numbers in it. In the end you should return an array
of neighbors added up. Please use JavaScript
<!doctype html>
<html>
<head>
<script>
function addNeighbors(arrr)
{
var lenn=arrr.length,i;
var array=new Array(lenn-1);
if(lenn%2==0)
{
for(i=0;i<lenn-1;i++)
array[i]=arrr[i]+arrr[i+1];
return array;
}
else
{
document.write("<br>"+"Enter array with only even
length"+"<br>");
}
}
function printresult(result)
{
document.write("<br>");
for(var j=0;j<result.length;j++)
document.write(result[j]+" ");
}
document.write("<br>"+"for array 1");
var result1=addNeighbors([1,2,3,4,5,6,7,8]);
printresult(result1)
document.write("<br>"+"for array 2");
var result2=addNeighbors([12,32,35,28,10,18,55]);
printresult(result2)
</script>
</head>
<body>
</body>
</html>
output:
Write a function called addNeighbors that takes an array of numbers and adds each number in...
In C++ Write a function called fillArray that will fill an array of any constantly declared array size variable with random numbers in the range of 1 - 100. Write a function called printArray that will print an array of any size. Write a third function called countEvens which will count and return the number of even numbers in the array. In main create an array that holds 25 ints. Use your functions to fill, print, and count the number...
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 C++ Write a function numberOfOddNumbers that takes an array of integers and its size (length) as parameters and then returns the number of the odd numbers found in the array. For example, if an array called list stores the following values: int list []= { 1,1, 8,6,9,4,3,9595,0 }; Then the call of numberOfOddNumbers (list,9) should return 5. If instead, the list had stored these values: int list2[] = { 2, 4, 6, 8, 10, 208 }; Then the call...
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
write an algorithm function called balance() in javascript that takes in a string and returns a strinf with balanced parantheses only. the string should be able to contain only parantheses, numbers, and letters. include comments of each portion of your code balance(“()()”) should return “()()” balance(“())”) should return “()” balance(“a(b)c”) should return “a(b)c” balance(“a(b)c())”) should return “a(b)c()”
Write a function that takes an array of integers as an argument and returns a value based on the sums of the even and odd numbers in the array. Let X = the sum of the odd numbers in the array and let Y = the sum of the even numbers. The function should return X – Y The signature of the function is: int f(int[ ] a) Examples if input array is return {1} 1 {1, 2} -1 {1,...
Write a function with two input parameters: an array of numbers and the size of the array (the number of elements). The function should return the count of even numbers in the array. For example, if the input to the function is the array [3, 2, 45, 56, 12], the function would return the integer 3. Use the following function header: int countEvens(int nums[], int size) { }
1.) Write a function called canMakeSum() that takes a sorted array of n integers and determines whether two distinct elements of the array add up to some specified value, "key". If so, return 1. Otherwise, return 0. The function signature is: int canMakeSum(int *array, int n, int key);
Write a function named stats, that takes an array and the number of elements in the array as arguments. It must compute and print the minimum value in the array, maximum value in the array and the average value of all the values inside the array. Your function MUST be named stats Your function has two parameters in the following order: an array of type double The number of elements in the array, type int Your function should NOT return...