Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created December 9, 2019 21:43
Show Gist options
  • Select an option

  • Save venelrene/0af3316cbb4c2ad127dc53e95bfa094d to your computer and use it in GitHub Desktop.

Select an option

Save venelrene/0af3316cbb4c2ad127dc53e95bfa094d to your computer and use it in GitHub Desktop.
Given an array of integers, remove the smallest value. Do not mutate the original array/list. If there are multiple elements with the same value, remove the one with a lower index. If you get an empty array/list, return an empty array/list. Don't change the order of the elements that are lef
def remove_smallest(numbers)
return numbers if numbers.empty?
numbers.dup.tap { |i| i.delete_at(numbers.index(numbers.min)) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment