Comparing version 0.2.1 to 0.2.2
@@ -0,15 +1,19 @@ | ||
'use strict'; | ||
var annotate = require('annotate'); | ||
var is = require('annois'); | ||
var funkit = require('funkit'); | ||
var keys = funkit.object.keys; | ||
var values = funkit.object.values; | ||
var fp = require('annofp'); | ||
var prop = fp.prop; | ||
var keys = fp.keys; | ||
var values = fp.values; | ||
var zip = annotate('zip', 'Converts given input into a zip'). | ||
on(is.array, is.array, function(a, b) { | ||
on([is.array], function() { | ||
var ret = []; | ||
var args = Array.prototype.slice.call(arguments); | ||
var i, len; | ||
for(i = 0, len = Math.min(a.length, b.length); i < len; i++) { | ||
ret.push([a[i], b[i]]); | ||
for(i = 0, len = Math.min.apply(null, args.map(prop('length'))); i < len; i++) { | ||
ret.push(extract(i, args)); | ||
} | ||
@@ -24,6 +28,16 @@ | ||
function extract(idx, arrays) { | ||
var ret = []; | ||
var i, len; | ||
for(i = 0, len = arrays.length; i < len; i++) { | ||
ret.push(arrays[i][idx]); | ||
} | ||
return ret; | ||
} | ||
var toObject = annotate('zip.toObject', 'Converts given zip into an object'). | ||
on(isZip, function(a) { | ||
var ret = {}; | ||
var i, len; | ||
@@ -45,5 +59,5 @@ a.forEach(function(v) { | ||
return is.array(a) && zips.length == a.length; | ||
return is.array(a) && zips.length === a.length; | ||
} | ||
module.exports = zip; |
@@ -5,12 +5,13 @@ { | ||
"author": "Juho Vepsalainen <bebraw@gmail.com>", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"dependencies": { | ||
"funkit": "0.7.7", | ||
"annois": "0.3.0", | ||
"annotate": "0.7.0" | ||
"annotate": "0.9.0", | ||
"annofp": "~0.2.2" | ||
}, | ||
"devDependencies": { | ||
"require-dir": "0.1.0", | ||
"annofuzz": "0.3.0", | ||
"annogenerate": "0.6.2" | ||
"annofuzz": "0.4.6", | ||
"annogenerate": "0.7.2", | ||
"annoops": "~0.2.0" | ||
}, | ||
@@ -17,0 +18,0 @@ "scripts": { |
@@ -13,4 +13,6 @@ [![build status](https://secure.travis-ci.org/annojs/zip.png)](http://travis-ci.org/annojs/zip) | ||
var o = {name: 'Joe', age: 123}; | ||
var o = {name: 'Joe', age: 123} | ||
var ozip = zip(o); // [['name', 'Joe'], ['age', 123]] | ||
var o2 = zip.toObject(ozip); // {name: 'Joe', age: 123} | ||
``` | ||
@@ -17,0 +19,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
var generate = require('annogenerate'); | ||
@@ -8,4 +10,3 @@ | ||
var fuzz = require('annofuzz')(generate); | ||
var funkit = require('funkit'); | ||
var equals = funkit.ops.equals; | ||
var deepeq = require('annoops').deepeq; | ||
@@ -15,8 +16,8 @@ var zip = require('../'); | ||
fuzz._amount = 100; | ||
fuzz(zip.toObject, function(op, a) { | ||
var res = op(a); | ||
return a.filter(function(v) { | ||
return equals(res[v[0]], v[1]); | ||
}).length == a.length; | ||
}); | ||
return deepeq(res[v[0]], v[1]); | ||
}).length === a.length; | ||
}, 100); |
@@ -0,8 +1,6 @@ | ||
'use strict'; | ||
var generate = require('annogenerate'); | ||
var fuzz = require('annofuzz')(generate); | ||
var is = require('annois'); | ||
var funkit = require('funkit'); | ||
var equals = funkit.ops.equals; | ||
var keys = funkit.object.keys; | ||
var values = funkit.object.values; | ||
var deepeq = require('annoops').deepeq; | ||
@@ -12,14 +10,13 @@ var zip = require('../'); | ||
fuzz._amount = 100; | ||
fuzz(zip, function(op, a, b) { | ||
if(!is.defined(b)) { | ||
a = keys(a); | ||
b = values(a); | ||
} | ||
// two arrays | ||
fuzz(zip, function(op) { | ||
var a = generate.array(); | ||
var b = generate.array(); | ||
var res = op(a, b); | ||
return res.filter(function(v, i) { | ||
return equals(v[0], a[i]) && equals(v[1], b[i]); | ||
}).length == res.length; | ||
}); | ||
return deepeq(v[0], a[i]) && deepeq(v[1], b[i]); | ||
}).length === res.length; | ||
}, 100); | ||
// TODO: figure out a nice invariant for generalized case!!! |
Sorry, the diff of this file is not supported yet
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
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
4812
76
22
4
+ Addedannofp@~0.2.2
+ Addedannofp@0.2.3(transitive)
+ Addedannomath@0.2.0(transitive)
+ Addedannotate@0.9.0(transitive)
+ Addedrequire-dir@0.1.0(transitive)
- Removedfunkit@0.7.7
- Removedfunkit@0.7.7(transitive)
Updatedannotate@0.9.0