church 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/church/array.rb +1 -1
- data/lib/church/version.rb +1 -1
- data/spec/array_spec.rb +5 -0
- metadata +1 -1
data/lib/church/array.rb
CHANGED
@@ -101,7 +101,7 @@ module Church
|
|
101
101
|
# Returns the index of the element within the collection, or nil if not found.
|
102
102
|
INDEX = -> coll, elem {
|
103
103
|
(indexer = -> i {
|
104
|
-
coll[i] == elem ? i : i > SIZE[
|
104
|
+
coll[i] == elem ? i : i > SIZE[coll] ? nil : indexer[i + 1]
|
105
105
|
})[0]
|
106
106
|
}
|
107
107
|
end
|
data/lib/church/version.rb
CHANGED
data/spec/array_spec.rb
CHANGED
@@ -104,4 +104,9 @@ describe 'INDEX' do
|
|
104
104
|
expect(INDEX['abc', 'b']).to be 1
|
105
105
|
expect(INDEX['abc', 'd']).to be nil
|
106
106
|
end
|
107
|
+
|
108
|
+
it "should find the indices of elements within arrays" do
|
109
|
+
expect(INDEX[[1, 2, 3], 3]).to be 2
|
110
|
+
expect(INDEX[[1, 2, 3], 4]).to be nil
|
111
|
+
end
|
107
112
|
end
|