Using array.delete(array.min) to delete one instance of a value
I'm trying to create a dice game program. I want to select one of the lowest out of five die, move it to a new array and remove the singular occurrence of that lowest dice from the original array. The problem is if there are more than one of the lowest die, this happens:
开发者_StackOverflowarray = %w[1,1,2,3,4]
new_array=[]
new_array.push(array.min) => 1
array.delete(array.min) => 2,3,4
new_array = array.sort.slice!(0..0)
or
new_array.push(array.sort!.shift)
精彩评论