Skip to content

Instantly share code, notes, and snippets.

@Dykam
Created March 25, 2011 22:11
Show Gist options
  • Save Dykam/887739 to your computer and use it in GitHub Desktop.
Save Dykam/887739 to your computer and use it in GitHub Desktop.
class Range
constructor: (@ranges...) ->
@rangePoints = (Array.prototype.concat (Range.fixRanges @ranges)...).sort()
@ranges = ([start, @rangePoints[i + 1]] for start, i in @rangePoints by 2)
intersect: (ranges...) ->
new Range @rangePoints.concat (Range.fixRanges ranges)...
@fixRanges: (ranges) -> range.rangePoints or range for range in ranges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment