I've just been putting together an audio meter by stacking bootstrap progress bars, and thought there was probably a better way, mathematically / logically, of achieving this.levels = (vumeter) ->  green = if vumeter % 50 < vumeter then 50 else vumeter  yellow = if vumeter % 85 < vumeter then 35 else vumeter - 50  red = if vumeter % 100 < vumeter then 15 else vumeter - 85  'green': green  'yellow': yellow  'red': red
Mathematical boundaries (audio meter)
coffeescript
Assuming that you want to replicate a classical audio meter (aka green bar grows until 50, then a yellow bar appears on top of green and grows until 85, then a red bar grows from there), then the easiest way to do this is with min and max functions.Assuming that vumeter should not be mutated here is the pseudo-code I came up with:green = min(vumeter, 50)yellow = max(min(vumeter - green, 35), 0)red = max(min(vumeter - green - yellow, 15), 0)