Lodash _.inRange() Method

The _.inRange() method takes a number, and checks to see if it is between given start and end parameters. If the end is not specified, then it is set equals to the start, and then start is set equals 0. If the start is greater than the end the parameters are swapped to support negative ranges.

Syntax:

_.inRange(number, start, end)

Parameters: This method accepts three parameters as mentioned above and described below:

  • number: This parameter holds the number to check.
  • start: This parameter holds the start value of the range.
  • end: This parameter holds the end value of the range.

Return Value: This method returns true if the number is in the range, else false.

Example 1:



Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.inRange method 
console.log(_.inRange(12, 10)); 
console.log(_.inRange(10, 12)); 
console.log(_.inRange(5.6, 5)); 
console.log(_.inRange(5.6, 6));

chevron_right


Output:

false
true
false
true

Example 2:  

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.inRange method 
console.log(_.inRange(2, 3, 5)); 
console.log(_.inRange(2, 2, 4)); 
console.log(_.inRange(4, 2, 4)); 
console.log(_.inRange(-2, -1, -5));

chevron_right


Output:

false
true
false
true

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.