EasyPro challengeTypeScript

Strategy

TypeScriptDesign PatternsBehavioralStrategy

Define a family of interchangeable algorithms, encapsulate each one, and select between them at runtime — a sorter that can switch between ascending and descending order without changing Sorter itself.

Implement `AscendingStrategy`/`DescendingStrategy` (sort(arr)) and Sorter.sort(arr), which delegates to whichever strategy it holds.

solve(arr, strategyName) picks the strategy by name and returns the sorted array (the original arr must be left untouched).

Sample tests

Test #1Ascending strategy
Input: [[3,1,2],"asc"]
Output: [1,2,3]
Test #2Descending strategy
Input: [[3,1,2],"desc"]
Output: [3,2,1]
Test #3Empty array
Input: [[],"asc"]
Output: []