Skip to content

Commit

Permalink
Merge pull request topazproject#534 from jstepien/enumerable-min-max
Browse files Browse the repository at this point in the history
Enumerable#{min,max}
  • Loading branch information
alex committed Mar 19, 2013
2 parents 7c53873 + e7f346f commit 131b97a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
20 changes: 20 additions & 0 deletions lib-topaz/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,24 @@ def reject(&block)
end
result
end

def min
inject do |minimum, current|
if minimum > current
current
else
minimum
end
end
end

def max
inject do |maximum, current|
if maximum < current
current
else
maximum
end
end
end
end
3 changes: 0 additions & 3 deletions spec/tags/core/enumerable/max_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
fails:Enumerable#max max should return the maximum element
fails:Enumerable#max return the maximum element (basics cases)
fails:Enumerable#max returns nil for an empty Enumerable
fails:Enumerable#max raises an ArgumentError for incomparable elements
fails:Enumerable#max return the maximum element (with block
fails:Enumerable#max returns the minimum for enumerables that contain nils
Expand Down
3 changes: 0 additions & 3 deletions spec/tags/core/enumerable/min_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
fails:Enumerable#min min should return the minimum element
fails:Enumerable#min return the minimun (basic cases)
fails:Enumerable#min returns nil for an empty Enumerable
fails:Enumerable#min raises an ArgumentError for incomparable elements
fails:Enumerable#min return the minimun when using a block rule
fails:Enumerable#min returns the minimum for enumerables that contain nils
Expand Down

0 comments on commit 131b97a

Please sign in to comment.