If an array has
nil items and we want to remove
nil items then we can use
As we can see
array2 does not have any nil items.
compact does not change the original array.
The original array1 is still containing
compact method returns a new array which has
nil items removed.