Fixed bugs pointed out by @kingdavidmartins
This commit is contained in:
@ -5,7 +5,10 @@ Checks if the given number falls in the given range.
|
|||||||
`end` is an optional parameter. If `end` is not given, the range is considered from `0` to `start`.
|
`end` is an optional parameter. If `end` is not given, the range is considered from `0` to `start`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const inRange = (n, start, end=null) => (end == null) ? (n>=0 && n<=start) : (n>=start && n<=end);
|
const inRange = (n, start, end=null) => {
|
||||||
|
if(end && start > end) end = [start, start=end][0]
|
||||||
|
return (end == null) ? (n>=0 && n<start) : (n>=start && n<end);
|
||||||
|
}
|
||||||
|
|
||||||
// inRange(3, 2, 5) -> true
|
// inRange(3, 2, 5) -> true
|
||||||
// inRange(3, 4) -> true
|
// inRange(3, 4) -> true
|
||||||
|
|||||||
Reference in New Issue
Block a user