Read here. Code on desktop. The coding workspace opens on screens 1024px and wider.
JavaScript interview question
In Range
easy10 min
Check whether a number lies inside a range whose lower boundary is included and upper boundary is excluded.
Requirements
Implement inRange(value, start, end). Return true when lower <= value < upper.
With two arguments, treat start as the upper boundary and use 0 as the other boundary.
If the boundaries are reversed, swap their roles. Equal boundaries form an empty range.
Support negative numbers and decimals. Non-finite values or boundaries, including NaN and Infinity, return false. Assume numeric arguments; do not coerce strings.
Examples
Example 1
Input: inRange(3, 2, 5)
Output: true
Example 2
Input: inRange(5, 2, 5)
Output: false
Example 3
Input: inRange(-2, -4)
Output: true
Test lower-inclusive, upper-exclusive numeric ranges.
What the tests check
Finds values inside the range
Includes the lower boundary and excludes the upper
Supports the two-argument form
Normalizes reversed boundaries
Supports a negative single boundary
Handles equal boundaries as an empty range
Supports decimals and negative ranges
Rejects non-finite values and boundaries
Handles zero and explicit undefined end consistently