Array#delete_at() : delete_at() es un método de clase Array que elimina los elementos de las arrays en el índice mencionado.
Syntax: Array.delete_at() Parameter: index - value at specific index value to delete Return: deleted element, nil - if the index value is out of range
Código #1: Ejemplo para el método delete_at()
Ruby
# Ruby code for delete_at() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, nil, nil, 50, 6] # delete puts "delete : #{a.delete_at(5)}\n\n" # delete # printing if no such element is found puts "delete : #{b.delete_at(0)}\n\n" # delete puts "delete : #{c.delete_at(20)}\n\n"
Producción :
delete : 6 delete : 1 delete :
Código #2: Ejemplo para el método delete_at()
Ruby
# Ruby code for delete_at() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, nil, nil, 50, 6] # delete puts "delete : #{a.delete_at(5)}\n\n" # delete # printing if no such element is found puts "delete : #{b.delete_at(0)}\n\n" # delete puts "delete : #{c.delete_at(20)}\n\n"
Producción :
delete : nil delete : delete : cat
Publicación traducida automáticamente
Artículo escrito por mayank5326 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA