Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ml-array-normed

Package Overview
Dependencies
Maintainers
7
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-array-normed - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.3.0](https://github.com/mljs/array/compare/ml-array-normed@1.2.0...ml-array-normed@1.3.0) (2020-04-17)
### Features
* add sumValue in normed ([a6e60c5](https://github.com/mljs/array/commit/a6e60c5d6e399aa3f24c30485d1be0b8bb373d1e))
# [1.2.0](https://github.com/mljs/array/compare/ml-array-normed@1.0.3...ml-array-normed@1.2.0) (2020-04-02)

@@ -8,0 +19,0 @@

6

package.json
{
"name": "ml-array-normed",
"version": "1.2.0",
"version": "1.3.0",
"description": "Get a normed array in an array",

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

"ml-array-max": "^1.1.2",
"ml-array-sum": "^1.1.2"
"ml-array-sum": "^1.1.3"
},
"gitHead": "767a39f38806810ec11bf3676948999500e35a36"
"gitHead": "f4d819343eda4106db474597986b1297d608c8f4"
}

@@ -49,2 +49,22 @@ import norm from '..';

it('should return the norm algorithm=sum sumValue=5', () => {
expect(norm([0], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([0]);
expect(norm([0, 0], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([
0,
0,
]);
expect(norm([-1, 1], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([
-1,
1,
]);
expect(norm([-1, 3], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([
-2.5,
7.5,
]);
expect(norm([1, 3], { algorithm: 'sum', sumValue: 5 })).toStrictEqual([
1.25,
3.75,
]);
});
it('should throw on invalid value', () => {

@@ -51,0 +71,0 @@ expect(() => norm()).toThrow(/input must be an array/);

@@ -10,2 +10,3 @@ import isArray from 'is-any-array';

* @param {number} [options.maxValue=1] new max value for algo max
* @param {number} [options.sumValue=1] new max value for algo absolute and sum
* @param {Array} [options.output=[]] specify the output array, can be the input array for in place modification

@@ -15,3 +16,3 @@ * @return {number}

export default function norm(input, options = {}) {
const { algorithm = 'absolute', maxValue = 1 } = options;
const { algorithm = 'absolute', maxValue = 1, sumValue = 1 } = options;
if (!isArray(input)) {

@@ -37,3 +38,3 @@ throw new Error('input must be an array');

case 'absolute': {
let absoluteSumValue = absoluteSum(input);
let absoluteSumValue = absoluteSum(input) / sumValue;
if (absoluteSumValue === 0) return input.slice(0);

@@ -55,6 +56,6 @@ for (let i = 0; i < input.length; i++) {

case 'sum': {
let sumValue = sum(input);
if (sumValue === 0) return input.slice(0);
let sumFactor = sum(input) / sumValue;
if (sumFactor === 0) return input.slice(0);
for (let i = 0; i < input.length; i++) {
output[i] = input[i] / sumValue;
output[i] = input[i] / sumFactor;
}

@@ -61,0 +62,0 @@ return output;

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