Asked • 04/16/20

JavaScript Averages in Arrays

I was doing an assignment and then I was stuck in this part of the question.How do use the function in javascript to generate the array using the parameters??

Instructions:

Given the following variable:

let array = [500, 523, 512, 504, 567, 543, 535, 586, 589, 508, 530, 578, 594, 538, 531, 599, 561, 593, 584, 550, 567, 567];
const ARRAY_LENGTH = 21;

Write some code to do the following:

  1. Write a function movingMean which takes two parameters, data and limit.
  2. This function should compute the mean value of the data array for the size limit.
  3. If the data array is larger than the size defined in the limit, you should delete items from the front of the array up until the array has only the no. of items defined by limit.
  4. Once that is done calculate the mean value of the array.
  5. Your function should return the mean value.
  6. To test your function, you should use array and ARRAY_LENGTH as the arguments for the 2 parameters.


1 Expert Answer

By:

James S. answered • 04/16/20

Tutor
5.0 (145)

Full-Stack Development Tutor Specializing in JavaScript Frameworks

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.