Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (40 pts) Write a JS program called assignment_2.js. In this script create the following functions: a. A function called larger that returns the larger

1. (40 pts) Write a JS program called "assignment_2.js". In this script create the following functions:

a. A function called larger that returns the larger of its two arguments. For example, the call larger(-2, 10) should return 10.

b. A function that returns the average of its two arguments. For example, the call average(-2,10) should return 4.

c. A function called averageLst that returns the average of all of the items in an array. For example, averageLst([4, 5, 7, 2]) should return 4.5. The function should take an array as it's argument.

d. A function called randNum, that accepts two numbers and returns a random number between the two values.

e. A function called median, that accepts three values and returns the median. The median of three values is the value that is greater than or equal to one of the other values and less than or equal to the remaining value.

f. A function called numberOfZeroes that returns the number of zeros in a given array. For example, the call numberOfZeroes([4, 0, false, 5, 0]) should return 2.

g. A function called cntOccurrences, that returns the number of occurrences of a given character in a string. For example, given the string "Rat-a-tat-tat" and the character t, your function should return 5.

h. A function called isPrime, that takes an array of numbers and returns an array containing the numbers that are prime. For example. The call isPrime([1, 5, 17, 25, 30]) should return [1, 5, 17].

2. (25 pts) Now we need to use our functions. Write calls to each of the functions you wrote above and use the following data for arguments:

a. 15, 100

b, 80, 50

c. [75, 60, 100, 90]

d. 10, 20

e. [-10, 25, 0]

f. [10, 0, 0, 0, false, true, 0, 0]

g. "Adrian Tillman was here", "a"

h. [1, 2, 3,5,7, 10, 12, 13, 15, 20]

3. (10 pts) Display the results. For each call, display the output such as:

"The result of calling numberOfZeroes with the values 10, 0, 0 is 2"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions

Question

Question Can any type of stock or securities be used in an ESOP?

Answered: 1 week ago

Question

Question Can a self-employed person adopt a money purchase plan?

Answered: 1 week ago