@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

@ -84,7 +84,11 @@
}, },
{ {
"note": "Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()`", "note": "Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()`",
"pr": "TODO" "pr": 2155
},
{
"note": "Add `shortZip()` to `lang_utils.ts`",
"pr": 2155
} }
] ]
}, },

View File

@ -50,3 +50,4 @@ export {
export { blockchainTests, BlockchainTestsEnvironment, describe } from './mocha_blockchain'; export { blockchainTests, BlockchainTestsEnvironment, describe } from './mocha_blockchain';
export { chaiSetup, expect } from './chai_setup'; export { chaiSetup, expect } from './chai_setup';
export { getCodesizeFromArtifact } from './codesize'; export { getCodesizeFromArtifact } from './codesize';
export { shortZip } from './lang_utils';

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]>;
}