How to delete an element from an array based off the user input in Ruby? -
i'm not sure i'm going wrong this. have array , user prompted question number should deleted array. number stored , result new array gets outputted deleted value.
def delete(number) = [1, 2, 1, 3, 1, 4, 2, 5] puts "please type number deleted?" number = gets result= a.delete(number) puts result end a.delete(number)
maybe ?
def delete(num,array) array.reject { |el| el == num } puts array end = [1, 2, 1, 3, 1, 4, 2, 5] puts "please type number deleted? array #{a}" number = gets delete(number.to_i,a)
Comments
Post a Comment