Ruby Array : Deleting Elements

Deleting Array Elements

chars = ["a", "b", "c"]
=> ["a", "b", "c"]
Approach 1 : Using index
colors.delete_at(1)
=> "b"

colors
=> ["a", "c"]

Approach 2: Using the actual value
colors = ["a", "b", "c"]
=> ["a", "b", "b"]
colors.delete("b")
=> "b"

colors
=> ["a", "c"]

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails