Refactor compact for code clarity

No logic change. The coverage tool complains about line `if (element != null) memo.push(element)` though it is tested with multiple test cases where the `arr` passed into `compactArray` looks like `[1,,,2]`. The reduced coverage is more like a bug in the coverage tool =/