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

allex_arrayoperationslowlevellib

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allex_arrayoperationslowlevellib - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

16

index.js

@@ -48,2 +48,17 @@ module.exports = function createArryOperations(extend, readPropertyFromDotDelimitedString, isFunction, Map, AllexJSONizingError) {

function lastfinder (propname, propval, result, item) {
var und;
if (propval !== und && readPropertyFromDotDelimitedString(item, propname) === propval) {
return item;
}
return result;
}
function findLastElementWithProperty(a, propname, propval) {
if (!(a && a.reduce)) {
return;
}
return a.reduce(lastfinder.bind(null, propname, propval), void 0);
}
function findElementAndIndexWithProperty(a, propname, propval) {

@@ -300,2 +315,3 @@ if (!(a && a.some)) {

findElementWithProperty: findElementWithProperty,
findLastElementWithProperty: findLastElementWithProperty,
findElementAndIndexWithProperty: findElementAndIndexWithProperty,

@@ -302,0 +318,0 @@ pivot : pivot,

11

package.json
{
"name": "allex_arrayoperationslowlevellib",
"version": "1.0.0",
"version": "1.1.0",
"description": "Various operations on Arrays",

@@ -22,2 +22,11 @@ "main": "index.js",

"devDependencies": {
"allex_avltreelowlevellib": "^1.1.0",
"allex_checkslowlevellib": "^1.1.4",
"allex_doublelinkedlistbaselowlevellib": "^1.1.0",
"allex_errorlowlevellib": "^1.0.0",
"allex_inheritlowlevellib": "^3.0.1",
"allex_jsonizingerrorlowlevellib": "^1.0.0",
"allex_maplowlevellib": "^1.0.0",
"allex_objectmanipulationlowlevellib": "^3.1.0",
"allex_stringmanipulationlowlevellib": "^3.4.2",
"chai": "3.x"

@@ -24,0 +33,0 @@ },

var expect = require('chai').expect,
inherit = require('allex_inheritlowlevellib').inherit,
checkftions = require('allex_checkslowlevellib'),
inherit = require('allex_inheritlowlevellib')(checkftions.isFunction, checkftions.isString).inherit,
AllexError = require('allex_errorlowlevellib')(inherit),
AllexJSONizingError = require('allex_jsonizingerrorlowlevellib')(AllexError,inherit),
checkftions = require('allex_checkslowlevellib'),
objmanip = require('allex_objectmanipulationlowlevellib')(checkftions),

@@ -58,2 +58,8 @@ stringmanip = require('allex_stringmanipulationlowlevellib')(checkftions.isString, checkftions.isNull),

expect(arrOp.difference([1, 2, 3, '4', '5'], [1, '4', 8, 9, 10])).to.deep.equal([2, 3, '5']);
var r = arrOp.difference ([1,2,3], [4,5,6]);
if (arrOp.contains (r, 4)) throw new Error('Result should not contain 4');
if (arrOp.contains (r, 5)) throw new Error('Result should not contain 5');
if (arrOp.contains (r, 6)) throw new Error('Result should not contain 6');
r = arrOp.difference([1,2],[2,3]);
if (arrOp.contains(r, 2)) throw new Error('Result should not contain 2');
});

@@ -71,2 +77,5 @@ it('union', function () {

});
it('findLastElementWithProperty', function () {
expect(arrOp.findLastElementWithProperty([1, {name: 'a', height: 15}, null, {name: 'a', a: 8}], 'name', 'a')).to.deep.equal({name: 'a', a: 8});
});
it('findElementAndIndexWithProperty', function () {

@@ -84,1 +93,66 @@ expect(arrOp.findElementAndIndexWithProperty([1, {name: 'a', height: 15}, null, {name: 'b', a: 8}], 'name', 'b')).to.deep.equal({element:{name: 'b', a: 8}, index: 3});

});
describe ('Test pivot', function () {
var numeric_source = [
{"symbol":0,"repetitions":5,"multiplier":1000},
{"symbol":0,"repetitions":4,"multiplier":500},
{"symbol":0,"repetitions":3,"multiplier":200},
{"symbol":2,"repetitions":5,"multiplier":300},
{"symbol":2,"repetitions":4,"multiplier":250},
{"symbol":3,"repetitions":5,"multiplier":250},
{"symbol":3,"repetitions":4,"multiplier":200},
{"symbol":4,"repetitions":5,"multiplier":220},
{"symbol":4,"repetitions":4,"multiplier":200},
{"symbol":4,"repetitions":3,"multiplier":160},
{"symbol":5,"repetitions":5,"multiplier":200},
{"symbol":5,"repetitions":4,"multiplier":180},
{"symbol":5,"repetitions":3,"multiplier":120},
{"symbol":6,"repetitions":5,"multiplier":180},
{"symbol":6,"repetitions":4,"multiplier":120},
{"symbol":6,"repetitions":3,"multiplier":75}];
var pivot = arrOp.pivot,
unpivot = arrOp.unpivot,
Pivoter = arrOp.Pivoter;
it ('Pivot test', function () {
var r = pivot(numeric_source, {
x_field: 'repetitions',
y_field: 'symbol',
value_field: 'multiplier',
init_empty_rows: false,
x_fields_list : ['2','3','4','5'],
to_y : function (s) { return parseInt(s); }
});
expect(r).to.be.an.array;
expect(r).to.have.length.of(7);
expect(r[1]).to.be.undefined;
});
it ('Pivot test', function () {
var p = new Pivoter({
x_field: 'repetitions',
y_field: 'symbol',
value_field: 'multiplier',
init_empty_rows: false,
x_fields_list : [2,3,4,5],
init_empty_rows : true
}),
r = p.pivot(numeric_source);
expect(r).to.be.an.array;
expect(r).to.have.length.of(7);
expect(r[1]).to.deep.equal(p.initializeEmptyPivotRecord());
var r1 = p.unpivot (r),
diff = arrOp.difference(r1, numeric_source, function (i1, i2) {
return i1.symbol == i2.symbol && i1.multiplier == i2.multiplier && i1.repetitions == i2.repetitions;
});
expect(diff.filter(function (item) {
return !!item.multiplier;
})).to.be.empty;
});
});
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