getInRange(x, bound1, bound2)
Write the function getInRange(x, bound1, bound2) which takes 3 int or float values -- x, bound1, and bound2, where bound1 is not necessarily less than bound2. If x is between the two bounds, just return it unmodified. Otherwise, if x is less than the lower bound, return the lower bound, or if x is greater than the upper bound, return the upper bound. For example:
getInRange(1, 3, 5) returns 3 (the lower bound, since 1 lies to the left of the range [3,5])
getInRange(4, 3, 5) returns 4 (the original value, since 4 is in the range [3,5])
getInRange(6, 3, 5) returns 5 (the upper bound, since 6 lies to the right of the range [3,5])
getInRange(6, 5, 3) also returns 5 (the upper bound, since 6 lies to the right of the range [3,5])
信息
- ID
- 1007
- 难度
- (无)
- 分类
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 通过率
- ?
- 上传者