0.0
No commit activity in last 3 years
No release in over 3 years
Given an array of integers, Array#reduce_ranges will return an array with all consecutive integers converted into ranges.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.6
>= 0
>= 0
 Project Readme

ReduceRanges

Reduce consecutive integers in an array into ranges.

Installation

Add this line to your application's Gemfile:

gem 'reduce_ranges'

And then execute:

$ bundle

Or install it yourself as:

$ gem install reduce_ranges

Usage

ReduceRanges adds an extension to the Array object. To use it, call #reduce_ranges on an array of integers:

[-3, -2, -1, 1, 3, 4, 5].reduce_ranges #=> [-3..-1, 1, 3..5]

Note that this only works on arrays of integers. If you call it on an array with any other kind of element, it will raise an error:

%w(what it do).reduce_ranges #=> TypeError
[1.0, 2.0, 3.0].reduce_ranges #=> TypeError
# etc..

Shout outs to @calyhre for the current implementation and @lkdjiin for his blog posts on the subject!i

Contributing

  1. Fork it ( https://github.com/jacobaweiss/reduce_ranges/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request