This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Zukowski
committed
Jan 23, 2017
1 parent
278e209
commit 32b18ee
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _curry3 from './internal/_curry3' | ||
|
||
/** | ||
* @name clamp | ||
* @signature Number -> Number -> Number -> Number | ||
* @since v0.18.0 | ||
* @description | ||
* Restricts a value to a given range (inclusive). | ||
* @example | ||
* clamp(1, 10, 5) // => 5 | ||
* clamp(1, 10, -5) // => 1 | ||
* clamp(1, 10, 15) // => 15 | ||
*/ | ||
export default _curry3(function clamp (lower, upper, value) { | ||
return value < lower ? lower : | ||
value > upper ? upper : | ||
value | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const test = require('ava') | ||
, { clamp } = require('../dist/redash') | ||
|
||
test('properly reports its arity (is ternary)', (t) => { | ||
t.is(clamp.length, 3) | ||
}) | ||
|
||
test('is curried', (t) => { | ||
t.is(typeof clamp(1), 'function') | ||
t.is(typeof clamp(1, 10), 'function') | ||
}) | ||
|
||
test('restricts values to the lower bound', (t) => { | ||
t.is(clamp(1, 10, -5), 1) | ||
}) | ||
|
||
test('restricts values to the upper bound', (t) => { | ||
t.is(clamp(1, 10, 15), 10) | ||
}) | ||
|
||
test('allows values between the lower and upper bound', (t) => { | ||
t.is(clamp(1, 10, 5), 5) | ||
}) |