ml-array-max
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -9,17 +9,17 @@ 'use strict'; | ||
function max(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 max = input[0]; | ||
for (var i = 1; i < input.length; i++) { | ||
if (input[i] > max) max = input[i]; | ||
} | ||
return max; | ||
var max = input[0]; | ||
for (var i = 1; i < input.length; i++) { | ||
if (input[i] > max) max = input[i]; | ||
} | ||
return max; | ||
} | ||
module.exports = max; |
{ | ||
"name": "ml-array-max", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Get the maximum value in an array", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import max from '..'; | ||
describe('array-max', () => { | ||
it('should return the max', () => { | ||
expect(max([0])).toBe(0); | ||
expect(max([1])).toBe(1); | ||
expect(max([1, 2])).toBe(2); | ||
expect(max([1, 2, 1])).toBe(2); | ||
expect(max([3, 2, 1])).toBe(3); | ||
}); | ||
it('should throw on invalid value', () => { | ||
expect(() => max()).toThrow(/input must be an array/); | ||
expect(() => max([])).toThrow(/input must not be empty/); | ||
}); | ||
it('should return the max', () => { | ||
expect(max([0])).toBe(0); | ||
expect(max([1])).toBe(1); | ||
expect(max([1, 2])).toBe(2); | ||
expect(max([1, 2, 1])).toBe(2); | ||
expect(max([3, 2, 1])).toBe(3); | ||
}); | ||
it('should throw on invalid value', () => { | ||
expect(() => max()).toThrow(/input must be an array/); | ||
expect(() => max([])).toThrow(/input must not be empty/); | ||
}); | ||
}); |
@@ -7,15 +7,15 @@ /** | ||
export default function max(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 max = input[0]; | ||
for (var i = 1; i < input.length; i++) { | ||
if (input[i] > max) max = input[i]; | ||
} | ||
return max; | ||
var max = input[0]; | ||
for (var i = 1; i < input.length; i++) { | ||
if (input[i] > max) max = input[i]; | ||
} | ||
return max; | ||
} |
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
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
3829
7