We are implementing algorithms for calculating the mean, median and mode of a dataset with JavaScript.

Before proceeding to coding, we briefly discuss how we can calculate each of these dataset properties.

Mean: in order to calculate the mean, all we have to do is to sum up all data points and divide by the number of data points. In other words, the mean, and more specifically the arithmetic mean (which is what we are calculating today), is what we usually call “the average” in everyday-life. Although, technically, mean, median, and mode are all kinds of averages, each trying to summarize the dataset with a single number representing a “typical” data point from the dataset.

Median: in order to get the median (the middle value), we first need to sort the dataset (conventionally in ascending order, but we would get the same result by sorting in descending order) and pick the data-point in the middle. If we had an even number of data points, we would get the mean of the 2 middle elements (by adding them and dividing by 2).

Mode: is the value in the dataset which occurs more frequently. If all values in the dataset appear with the same frequency, then the dataset has no mode. It is also possible for a dataset to have more than one modes.

Mean, median and mode, are different approaches for calculating the “typical” or “central” value of a dataset. That’s why they are also called measures of central tendency. Usually, they are used in conjunction with measures of spread (or measures of dispersion), in order to get the degree to which data is distributed around the center. Such measures of spread are the Range (which is the difference between the maximum and minimum value of the dataset) and Variance (or Standard Deviation which is the square root of Variance).

In this video, we are implementing algorithms for measures of central tendency. Feel free to expand on this, maybe by also calculating measures of spread and/or other statistical values. You could even take it a step further by creating a user interface such as a statistics calculator, which allows the user to enter a dataset and calculates and presents to the user a number of statistical values for the given dataset.

#javascript

Mean, Median and Mode with JavaScript
20.55 GEEK