From e209990682bc921b1e1de6ae8f64f6843a22ba14 Mon Sep 17 00:00:00 2001 From: glhrmv Date: Fri, 22 Sep 2017 20:06:43 +0100 Subject: [PATCH] Add is.withinRange --- index.js | 2 ++ test.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/index.js b/index.js index 132db41..8aa82f2 100644 --- a/index.js +++ b/index.js @@ -148,4 +148,6 @@ const typedArrayTypes = new Set([ ]); is.typedArray = x => typedArrayTypes.has(getObjectType(x)); +is.withinRange = (x, arr) => (x > Math.min.apply(Math, arr)) && (x < Math.max.apply(Math, arr)); + module.exports = is; diff --git a/test.js b/test.js index 7868637..99917ba 100644 --- a/test.js +++ b/test.js @@ -293,3 +293,10 @@ test('is.typedArray', t => { t.false(m.typedArray([])); t.false(m.typedArray({})); }); + +test('is.withinRange', t => { + const x = 3; + const arr = [0, 5]; + + t.true(m.withinRange(x, arr)); +});