Check if Number is within a Given Range

Published by Helen Yu in

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

Examples

isInRange(4, array('min' => 0, 'max' => 5 )) ➞ true

isInRange(4, array('min' => 4, 'max' => 5 )) ➞ true

isInRange(4, array('min' => 6, 'max' => 10 )) ➞ false

isInRange(5, array('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.