Ruby - Arrays
Which Ruby code snippet correctly creates a new array from arr without any nil values?
arr = [4, nil, 7, nil, 9]
Which Ruby code snippet correctly creates a new array from arr without any nil values?
arr = [4, nil, 7, nil, 9]
compact returns a new array without nil values, leaving original unchanged.compact!compact! modifies the original array in place and returns nil if no changes were made.arr.delete(nil) removes nil from original array and returns last deleted element, not a new array.reject(&:nil!) is invalid syntax.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions