Socket
Socket
Sign inDemoInstall

ml-array-mean

Package Overview
Dependencies
Maintainers
5
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-array-mean - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

CHANGELOG.md

22

lib/index.js

@@ -9,17 +9,17 @@ 'use strict';

function mean(input) {
if (!Array.isArray(input)) {
throw new Error('input must be an array');
}
if (!Array.isArray(input)) {
throw new Error('input must be an array');
}
if (input.length === 0) {
throw new Error('input must not be empty');
}
if (input.length === 0) {
throw new Error('input must not be empty');
}
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += input[i];
}
return sum / input.length;
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += input[i];
}
return sum / input.length;
}
module.exports = mean;
{
"name": "ml-array-mean",
"version": "1.0.1",
"version": "1.0.2",
"description": "Get the average value in an array",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import mean from '..';
describe('array-mean', () => {
it('should return the mean', () => {
expect(mean([0])).toBe(0);
expect(mean([1])).toBe(1);
expect(mean([1, 2])).toBe(1.5);
expect(mean([1, 2, 1])).toBe(4 / 3);
expect(mean([3, 2, 1])).toBe(2);
});
it('should return the mean', () => {
expect(mean([0])).toBe(0);
expect(mean([1])).toBe(1);
expect(mean([1, 2])).toBe(1.5);
expect(mean([1, 2, 1])).toBe(4 / 3);
expect(mean([3, 2, 1])).toBe(2);
});
it('should throw on invalid value', () => {
expect(() => mean()).toThrow(/input must be an array/);
expect(() => mean([])).toThrow(/input must not be empty/);
});
it('should throw on invalid value', () => {
expect(() => mean()).toThrow(/input must be an array/);
expect(() => mean([])).toThrow(/input must not be empty/);
});
});

@@ -7,15 +7,15 @@ /**

export default function mean(input) {
if (!Array.isArray(input)) {
throw new Error('input must be an array');
}
if (!Array.isArray(input)) {
throw new Error('input must be an array');
}
if (input.length === 0) {
throw new Error('input must not be empty');
}
if (input.length === 0) {
throw new Error('input must not be empty');
}
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += input[i];
}
return sum / input.length;
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += input[i];
}
return sum / input.length;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc