Check if Number is within a Given Range

Published by Matt in

Given a number and a hash with min and max properties, return true if the number lies within the given range (inclusive).

Examples

is_in_range(4, { min: 0, max: 5 }) ➞ true

is_in_range(4, { min: 4, max: 5 }) ➞ true

is_in_range(4, { min: 6, max: 10 }) ➞ false

is_in_range(5, { min: 5, max: 5 }) ➞ true

Notes

  • Numbers can be positive or negative, and they may not be integers.
  • You can assume min <= max is always true.
  • If you get stuck on a challenge, find help in the Resources tab.
  • If you're really stuck, unlock solutions in the Solutions tab.
Watch a quick demo on how Edabit works.