Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CoffeeScript comparison range


May 09, 2021 CoffeeScript


Table of contents


The comparison range

Problem

If you want to know if a variable is within a given range.

Solution

Compare syntax using CoffeeScript's embellishments.

maxDwarfism = 147
minAcromegaly = 213

height = 180

normalHeight = maxDwarfism < height < minAcromegaly
# => true

Discuss

This is a great feature to draw from Python. With this feature, you don't have to write a complete comparison like this:

normalHeight = height > maxDwarfism && height < minAcromegaly

CoffeeScript is more intuitive by supporting two comparisons, like a comparison expression in writing math.

Related tutorials

python Basic Tutorial