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

protoblast

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protoblast - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## 0.3.1 (2016-07-02)
* Fix protoblast version bug
* Add static `Number.calculateNormalizeFactors` and `Number.normalize` methods
* Add `Math.removeOutliers(arr)` which returns a new array without outliers
* Add `Number.denormalize`
## 0.3.0 (2016-06-22)

@@ -2,0 +9,0 @@

3

lib/init.js

@@ -89,2 +89,3 @@ module.exports = function BlastInit(modifyPrototype) {

if (Globals.__Protoblast) {
// If we don't have to modify the prototype, or if it's already done, return the existing collection

@@ -102,3 +103,3 @@ if (!modifyPrototype || (modifyPrototype && Globals.__Protoblast.modifyPrototype)) {

// If the earlier loaded protoblast instance has a higher patch, we can safely use that
if (other_ver.patch > version.patch) {
if (other_ver.patch >= version.patch) {
return Globals.__Protoblast;

@@ -105,0 +106,0 @@ }

@@ -714,2 +714,74 @@ module.exports = function BlastMath(Blast, Collection) {

/**
* Remove outliers from the given array, return a new one
*
* @author Jelle De Loecker <jelle@kipdola.be>
* @since 0.3.1
* @version 0.3.1
*
* @param {Array} arr The input array
* @param {Boolean} clip Clip outliers to highest or lowest value
*
* @return {Array}
*/
Blast.defineStatic('Math', 'removeOutliers', function removeOutliers(arr, clip) {
var filtered_values,
max_value,
min_value,
result,
values,
iqr,
q1,
q3,
x,
i;
// Clone the array to determine max and min values
values = arr.slice(0);
// And create a new array
result = [];
// Sort the numbers
Blast.Bound.Array.flashsort(values);
/* Then find a generous IQR. This is generous because if (values.length / 4)
* is not an int, then really you should average the two elements on either
* side to find q1.
*/
q1 = values[Math.floor((values.length / 4))];
// Likewise for q3.
q3 = values[Math.ceil((values.length * (3 / 4)))];
iqr = q3 - q1;
// Then find min and max values
max_value = q3 + iqr * 1.5;
min_value = q1 - iqr * 1.5;
for (i = 0; i < arr.length; i++) {
x = arr[i];
if (x > max_value) {
if (clip) {
x = max_value;
} else {
continue;
}
} else if (x < min_value) {
if (clip) {
x = min_value;
} else {
continue;
}
}
result.push(x);
}
return result;
});
};

@@ -71,2 +71,75 @@ module.exports = function BlastNumber(Blast, Collection) {

/**
* Calculate numbers needed to normalize data
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.3.1
* @version 0.3.1
*
* @param {Array} input Input values
* @param {Array} scale
*
* @return {Object}
*/
Blast.defineStatic('Number', 'calculateNormalizeFactors', function calculateNormalizeFactors(input, scale) {
return {
input_min : Math.min.apply(Math, input),
input_max : Math.max.apply(Math, input),
scale_min : Math.min.apply(Math, scale),
scale_max : Math.max.apply(Math, scale)
};
});
/**
* Normalize data using the given scale
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.3.1
* @version 0.3.1
*
* @param {Array} input Input values
* @param {Array} scale
*
* @return {Array}
*/
Blast.defineStatic('Number', 'normalize', function normalize(input, scale) {
var result = new Array(input.length),
i;
if (Array.isArray(scale)) {
scale = Blast.Bound.Number.calculateNormalizeFactors(input, scale);
}
for (i = 0; i < input.length; i++) {
result[i] = scale.scale_min + (((input[i] - scale.input_min) * (scale.scale_max - scale.scale_min)) / (scale.input_max - scale.input_min));
}
return result;
});
/**
* Denormalize data using the given scale
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.3.1
* @version 0.3.1
*
* @param {Array} input Input values
* @param {Array} scale
*
* @return {Array}
*/
Blast.defineStatic('Number', 'denormalize', function denormalize(input, scale) {
var result = new Array(input.length),
i;
for (i = 0; i < input.length; i++) {
result[i] = input * (scale.input_max - scale.input_min) + scale.input_min;
}
return result;
});
/**
* Return a string representing the source code of the number.

@@ -73,0 +146,0 @@ *

{
"name": "protoblast",
"description": "Add useful methods to native objects",
"version": "0.3.0",
"version": "0.3.1",
"author": "Jelle De Loecker <jelle@develry.be>",

@@ -6,0 +6,0 @@ "keywords": [

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