diff --git a/src/number/number.util.test.ts b/src/number/number.util.test.ts index 87302439..8794f995 100644 --- a/src/number/number.util.test.ts +++ b/src/number/number.util.test.ts @@ -27,6 +27,7 @@ test.each([ [2, 2, 1, false], [2, 2, 2, false], [2, Number.NEGATIVE_INFINITY, 3, true], + ['2020-01-03', '2020-01-01', '2020-01-05', true], ])('_isBetween(%s, %s, %s) === %s', (n, min, max, result) => { expect(_isBetween(n, min, max)).toBe(result) }) diff --git a/src/number/number.util.ts b/src/number/number.util.ts index 0c30280f..717737ce 100644 --- a/src/number/number.util.ts +++ b/src/number/number.util.ts @@ -34,11 +34,14 @@ export function _runLessOften(percent: number): boolean { * _isBetween(3, 1, 5) // true * _isBetween(5, 1, 5) // false * _isBetween(7, 1, 5) // false + * + * Also works with strings: + * _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true */ -export function _isBetween( - x: number, - min: number, - max: number, +export function _isBetween( + x: T, + min: T, + max: T, incl: Inclusiveness = '[)', ): boolean { if (incl === '[)') { @@ -48,7 +51,6 @@ export function _isBetween( } else if (incl === '(]') { return x > min && x <= max } - // () return x > min && x < max }