reduce_ranges 0.9.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/reduce_ranges.rb +8 -10
- data/lib/reduce_ranges/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5ed4f039e700600468cf12845b3b69aac354f2
|
4
|
+
data.tar.gz: e4bb98db6d0eae3a67edc78b3aa33f5e4b0708b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da2a58c7d36e5201e34f4791b31cd4c91742e58c531c4863f054b8e03747c56a08a55c548aef5d2cd8a1a8ac788cef30f9df8c1786901a9937e5db3dab8065e6
|
7
|
+
data.tar.gz: 263ed93ac5922bd9058ed43ac13ce6e17ec72400df8465acfe09c9f1f6f94c50ea8e2b36326d711a2e69e445aaaf8a815ec0ef3426deaeda773fb505b43c4801
|
data/README.md
CHANGED
@@ -30,6 +30,8 @@ Note that this only works on arrays of integers. If you call it on an array with
|
|
30
30
|
# etc..
|
31
31
|
```
|
32
32
|
|
33
|
+
Shout outs to @Calyhre for the current implementation and @lkdjiin for his blog posts on the subject!
|
34
|
+
|
33
35
|
## Contributing
|
34
36
|
|
35
37
|
1. Fork it ( https://github.com/jacobaweiss/reduce_ranges/fork )
|
data/lib/reduce_ranges.rb
CHANGED
@@ -2,17 +2,15 @@ require 'reduce_ranges/version'
|
|
2
2
|
|
3
3
|
class Array
|
4
4
|
def reduce_ranges
|
5
|
-
|
5
|
+
raise TypeError unless all? { |el| el.is_a?(Fixnum) }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
range_index += 1
|
14
|
-
end
|
15
|
-
arr[index..range_index-1] = (arr[index]..arr[range_index-1]) unless index == range_index - 1
|
7
|
+
results = []
|
8
|
+
temp = [self[0]]
|
9
|
+
self[1..-1].each do |e|
|
10
|
+
temp << e && next if temp.last == e - 1
|
11
|
+
results << (temp[1] ? (temp[0]..temp.last) : temp[0])
|
12
|
+
temp = [e]
|
16
13
|
end
|
14
|
+
results << (temp[1] ? (temp[0]..temp.last) : temp[0])
|
17
15
|
end
|
18
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reduce_ranges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@jacobaweiss"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|