Refactor Time library to use valueBefore/valueAfter (#4555)

Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Hadrien Croubois
2023-09-06 04:19:21 +02:00
committed by GitHub
parent bb7ca7d151
commit 87f7a2cd42
11 changed files with 203 additions and 45 deletions

16
test/helpers/iterate.js Normal file
View File

@ -0,0 +1,16 @@
// Map values in an object
const mapValues = (obj, fn) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn(v)]));
// Array of number or bigint
const max = (...values) => values.slice(1).reduce((x, y) => (x > y ? x : y), values[0]);
const min = (...values) => values.slice(1).reduce((x, y) => (x < y ? x : y), values[0]);
// Cartesian product of a list of arrays
const product = (...arrays) => arrays.reduce((a, b) => a.flatMap(ai => b.map(bi => [...ai, bi])), [[]]);
module.exports = {
mapValues,
max,
min,
product,
};