Skip to content

Commit

Permalink
first and last should return nil when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed Apr 24, 2024
1 parent 693c67e commit 8f8d3c8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/sorted_containers/sorted_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def delete(key)
#
# @return [Array] A two-element array containing the key and value of the first key-value pair.
def first
return nil if @sorted_array.empty?
key = @sorted_array.first
[key, @hash[key]]
end
Expand All @@ -66,6 +67,7 @@ def first
#
# @return [Array] A two-element array containing the key and value of the first key-value pair.
def last
return nil if @sorted_array.empty?
key = @sorted_array.last
[key, @hash[key]]
end
Expand Down

0 comments on commit 8f8d3c8

Please sign in to comment.