Difficulty: 4/10Array.prototype.sort, Comparator Functions, ImmutabilityUsing a number:CopyUsing strings:CopyScenario Questions0-2 years experience1We have a list of user objects like `{ name: 'Alice', age: 25 }` fetched from an API. We need to display them in a table sorted by age ascending. How would you write the sort logic, and what's a common trap to avoid regarding the original array?2Imagine you have an array of product objects with a `price` property. If you just call `.sort()` without passing any arguments, what happens to prices like 9, 100, and 20? How do you fix that?2-5 years experience1In our React app, we have a state array of transaction objects. A developer wrote `const sorted = transactions.sort((a, b) => b.amount - a.amount)` and passed it to a component, but the UI isn't re-rendering when the sort order changes. What's going on here, and how would you fix it?Follow-up QuestionsWhat happens if some of the objects are missing the key you are sorting by?How would you modify your solution to sort by multiple fields, like sorting by last name, then first name?How does JavaScript's sort handle stability, and why does that matter when sorting by multiple fields?Suggest Improvement