Solve a classic array manipulation problem, focusing on handling edge cases and structuring your code with clean helper functions.