Files
openzeppelin-contracts/test/helpers/iterate.js
2024-02-12 16:34:07 +00:00

16 lines
555 B
JavaScript

// Map values in an object
const mapValues = (obj, fn) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn(v)]));
// Cartesian product of a list of arrays
const product = (...arrays) => arrays.reduce((a, b) => a.flatMap(ai => b.map(bi => [...ai, bi])), [[]]);
const unique = (...array) => array.filter((obj, i) => array.indexOf(obj) === i);
const zip = (...args) =>
Array.from({ length: Math.max(...args.map(array => array.length)) }, (_, i) => args.map(array => array[i]));
module.exports = {
mapValues,
product,
unique,
zip,
};