refactored the compact method to push instead of splice the original input array