Ruby - Arrays
Consider this Ruby code snippet:
arr = [1, nil, 2, nil, 3] arr.compact puts arr.inspect
Why does the output still include nil values?
Consider this Ruby code snippet:
arr = [1, nil, 2, nil, 3] arr.compact puts arr.inspect
Why does the output still include nil values?
compact behaviorcompact returns a new array without nil values but does not change the original array.arr still has nilarr.compact was called without assignment, arr remains unchanged and still contains nil.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions