Ruby - Arrays
Which of the following is the correct syntax to remove nil values from an array arr without changing arr itself?
arr = [1, nil, 2, nil, 3]
Which of the following is the correct syntax to remove nil values from an array arr without changing arr itself?
arr = [1, nil, 2, nil, 3]
compact returns a new array without nil values and does not modify the original array.compact!compact! modifies the original array, so it changes arr. delete(nil) removes nil but modifies arr. remove_nil is not a Ruby method.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions