DEV Community

Discussion on: JavaScript One-Liners That Make Me Excited

Collapse
 
jacobmgevans profile image
Jacob Evans • Edited
isInRange = (a, b, c) => [...Array(c - a +1)].map((e, i) => i + a).indexOf(b) !== -1

I did this one for a challenge. It finds if a number is in a range of two other numbers so find if b is in range of a to c

Collapse
 
nestedsoftware profile image
Nested Software • Edited

Wouldn't you just check b >= a && b <= c ?

Collapse
 
jacobmgevans profile image
Jacob Evans

That was definitely a way to do it. However, I am pretty sure that only works with constraints on the range values, and the way I wanted to solve it was to be sure it could handle any range.

I could be wrong which in that case, I will certainly remember this way lol

Thread Thread
 
jacobmgevans profile image
Jacob Evans

Nope to me lol, you're just right and I am pretty sure that works for any size range not just that but the
Big O is significantly better ahahaha!