Comparing version 0.2.7 to 0.3.0
@@ -25,2 +25,17 @@ /** | ||
/** | ||
Transpose an Array of Arrays. | ||
E.g.: | ||
zip([ | ||
[1, 2, 3], | ||
[2, 4, 6], | ||
[1, 4, 8], | ||
[10, 100, 1000], | ||
]) | ||
-> [[1, 2, 1, 10], [2, 4, 4, 100], [3, 6, 8, 1000]] | ||
*/ | ||
export declare function zip<T>(itemss: T[][]): T[][]; | ||
/** | ||
Call `fn` with each item in `items`, and flatten the results into a single array. | ||
@@ -173,8 +188,19 @@ | ||
{key: 'lastname', value: 'Brown'}, | ||
]) => [ | ||
{firstname: 'Chris', lastname: 'Brown'}, | ||
] | ||
]) | ||
-> {firstname: 'Chris', lastname: 'Brown'} | ||
*/ | ||
export declare function toObject<T>(items: T[], nameKey?: string, valueKey?: string): {}; | ||
/** | ||
Convert an Array of [string, T] tuples to an object. | ||
E.g.: | ||
tuplesToObject([ ['firstname', 'Chris'], ['lastname', 'Brown'] ]) | ||
-> {firstname: 'Chris', lastname: 'Brown'} | ||
*/ | ||
export declare function tuplesToObject<T>(tuples: [string, T][]): { | ||
[index: string]: T; | ||
}; | ||
/** | ||
Groups contiguous equivalent items together. | ||
@@ -181,0 +207,0 @@ |
46
index.js
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/** | ||
@@ -32,2 +33,24 @@ Push each item in `items` onto the end of `array`. | ||
/** | ||
Transpose an Array of Arrays. | ||
E.g.: | ||
zip([ | ||
[1, 2, 3], | ||
[2, 4, 6], | ||
[1, 4, 8], | ||
[10, 100, 1000], | ||
]) | ||
-> [[1, 2, 1, 10], [2, 4, 4, 100], [3, 6, 8, 1000]] | ||
*/ | ||
function zip(itemss) { | ||
var lengths = itemss.map(function (items) { return items.length; }); | ||
var minLength = Math.min.apply(Math, lengths); | ||
return range(minLength).map(function (index) { | ||
return itemss.map(function (items) { return items[index]; }); | ||
}); | ||
} | ||
exports.zip = zip; | ||
/** | ||
Call `fn` with each item in `items`, and flatten the results into a single array. | ||
@@ -312,5 +335,4 @@ | ||
{key: 'lastname', value: 'Brown'}, | ||
]) => [ | ||
{firstname: 'Chris', lastname: 'Brown'}, | ||
] | ||
]) | ||
-> {firstname: 'Chris', lastname: 'Brown'} | ||
*/ | ||
@@ -328,2 +350,20 @@ function toObject(items, nameKey, valueKey) { | ||
/** | ||
Convert an Array of [string, T] tuples to an object. | ||
E.g.: | ||
tuplesToObject([ ['firstname', 'Chris'], ['lastname', 'Brown'] ]) | ||
-> {firstname: 'Chris', lastname: 'Brown'} | ||
*/ | ||
function tuplesToObject(tuples) { | ||
var object = {}; | ||
tuples.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return object[key] = value; | ||
}); | ||
return object; | ||
} | ||
exports.tuplesToObject = tuplesToObject; | ||
/** | ||
Groups contiguous equivalent items together. | ||
@@ -330,0 +370,0 @@ |
{ | ||
"name": "tarry", | ||
"version": "0.2.7", | ||
"version": "0.3.0", | ||
"description": "Utility library for manipulating JavaScript Arrays", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"mocha-lcov-reporter": "*", | ||
"typescript": "next" | ||
"typescript": "*" | ||
}, | ||
@@ -27,0 +27,0 @@ "scripts": { |
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
18329
528