Ruby - Arrays
What is the output of the following Ruby code?
arr = [nil, 5, nil, 10] new_arr = arr.compact puts new_arr.inspect puts arr.inspect
What is the output of the following Ruby code?
arr = [nil, 5, nil, 10] new_arr = arr.compact puts new_arr.inspect puts arr.inspect
compact returnscompact returns a new array without nil values, so new_arr is [5, 10].arr remains unchanged as [nil, 5, nil, 10].15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions