62.7k views
2 votes
Given a number n, return true if n is in the range 1..10, inclusive. Unless "outsideMode" is true, in which case return true if the number is less or equal to 1, or greater or equal to 10.

A in1To10(5, false) → true
B in1To10(11, false) → false
C in1To10(11, true) → true

1 Answer

4 votes

Final answer:

To solve this question, verify if the number n is within the range 1 to 10 when outsideMode is false, or is <= 1 or >= 10 when outsideMode is true. Case A results in true, B in false, and C in true.

Step-by-step explanation:

The question is asking to determine if a given number n is within a specific range based on the parameter "outsideMode". If outsideMode is false, then n must be between 1 and 10, inclusive, to return true. If outsideMode is true, then n should either be less than or equal to 1, or greater than or equal to 10, to return true.

Let's analyze the provided cases:

  • A: in1To10(5, false) should return true because 5 is within the range 1 to 10.
  • B: in1To10(11, false) should return false because 11 is not within the range 1 to 10.
  • C: in1To10(11, true) should return true because 11 is greater than or equal to 10, which is valid in outsideMode.

User Michael Konietzka
by
8.6k points