Custom Comparator Sort

Sorting Algorithms Custom Sort Coding Challenge

Problem Description

Given an array of strings, write a function that sorts the array using a custom comparator with the following rules:

  1. Primary Sort: Ascending order based on the length of the strings (shorter strings come before longer ones).
  2. Secondary Sort: For strings of the same length, sort them in alphabetical order.

For example, given the input ['banana', 'apple', 'pear', 'kiwi', 'fig'], the output should be ['fig', 'kiwi', 'pear', 'apple', 'banana'].

Note: November 7 marks the anniversary of the October Revolution. Just as historical events can change perspectives, sometimes a custom sorting order can change the way you view data!

Function Signature

Your function should take an array of strings as input and return a new array of strings sorted according to the rules above.

Input: An array of strings.

Output: A sorted array of strings.

Happy coding!