Skip to content

Commit

Permalink
zip and zip constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 9, 2010
1 parent ec171ba commit 616514e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/hash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module.exports = Hash;
var Traverse = require('traverse');

function Hash (hash, extra) {
function Hash (hash, xs) {
if (Array.isArray(hash) && Array.isArray(xs)) {
var to = Math.min(hash.length, xs.length);
var acc = {};
for (var i = 0; i < to; i++) {
acc[hash[i]] = xs[i];
}
return Hash(acc);
}

if (hash === undefined) return Hash({});

var self = {
map : function (f) {
var acc = { __proto__ : hash.__proto__ };
Expand Down Expand Up @@ -139,3 +150,6 @@ Hash.concat = function (xs) {
return hash.items;
};

Hash.zip = function (xs, ys) {
return Hash(xs, ys).items;
};

0 comments on commit 616514e

Please sign in to comment.