In celebration of this day, implement a merge sort algorithm that can sort an array of integers either in ascending or descending order based on a given flag. Your task is to write a function that takes an unsorted array and a boolean flag (e.g., true
for ascending and false
for descending) and returns a new sorted array.
For input array: [34, 7, 23, 32, 5, 62]
and ascending = true
, the output should be [5, 7, 23, 32, 34, 62]
.
Happy coding and enjoy this holiday-inspired challenge!