ml-array-mean
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -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; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3841
7
1