@0x/contracts-test-utils: Add shortZip().

This commit is contained in:
Lawrence Forman
2019-09-18 18:33:44 -04:00
committed by Lawrence Forman
parent 993f05d5ac
commit b4b6d4d969
3 changed files with 15 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
import * as _ from 'lodash';
/**
* _.zip() that clips to the shortest array.
*/
export function shortZip<T1, T2>(a: T1[], b: T2[]): Array<[T1, T2]> {
const minLength = Math.min(a.length, b.length);
return _.zip(a.slice(0, minLength), b.slice(0, minLength)) as Array<[T1, T2]>;
}