# How to Implement JavaScript for Statistics Method

[post-views]

Over these past few weeks, I’ve learned that JavaScript is an extremely useful programming language. In this blog, we will see how we can use JavaScript to implement statistical methods into our programs.

As you can probably imagine, there exist a couple libraries for statistical methods inside JavaScript. One of them is Simple Statistics. Here’s the link for the documentation for this library:
https://simplestatistics.org/

I will give a basic demonstration of some of the simpler statistical methods.

## min and max

```				```
min(x: Array<number>): number
```
```

(max is written in the same way, just swap min with max)

min and max return the smallest/largest number in an array. The only parameter is that you input an array of numbers.

## sum

```				```
sum(x:Array<number>): number
```
```

sum returns the sum of all the numbers in an array. Again, the only parameter is that you input an array of numbers.

## mean

```				```
mean(x: Array<number>): number
```
```

Mean returns the average of all the numbers in an array. The only parameter is that you input an array of numbers.

## variance

```				```
variance(x: Array<number>): number
```
```

Variance returns the sum of squared deviations from all the numbers in an array. The only parameter is that you input an array of numbers.

## zScore

```				```
zScore(x: number, mean: number, standardDeviation: number): number
```
```

zScore measures the score above or below the mean. For this, you need only provide the x (observed value), the mean (mu), and the standard deviation (sigma).

As you can see from these examples, Simple Statistics is a very intuitive JavaScript library. If you have any interest in this library, you can install it with this terminal command (assuming you have node.js):

```				```
npm install --save simple-statistics
```
```

Again, here is the link to the documentation if you need it:
https://simplestatistics.org/

In researching for this blog, I also found another library, jstat. This blog is already long enough, so I will not be delving into it, but here’s the documentation for that library if you need it:
https://jstat.github.io/overview.html

This has been Warren Ball, data science intern at iSmile Technologies. Thanks for reading, I hope this helps.

## Related articles you may would like to read

### Calculate Your DataOps ROI with Ease!

Simplify your decision-making process with the DataOps ROI Calculator, optimize your data management and analytics capabilities.

### Don't Miss Out on This Exclusive Webinar!

Discover how to optimize your IT operations and drive business success with our exclusive webinar.

### Find our Resources

##### Proposals

Know the specific resource requirement for completing a specific project with us.

##### Blog

Keep yourself updated with the latest updates about Cloud technology, our latest offerings, security trends and much more.

##### Webinar

Gain insights into latest aspects of cloud productivity, security, advanced technologies and more via our Virtual events.

ISmile Technologies delivers business-specific Cloud Solutions and Managed IT Services across all major platforms maximizing your competitive advantage at an unparalleled value.