Build sorting behavior for a list of comments.
Each comment contains at least these fields:
id: a string or integeruserId: a string or integertimestamp: an ISO-formatted string or epoch millisecondscontent: a stringRequirements:
timestamp or userId.asc) and descending (desc) order.localStorage.Provide the central implementation in pseudocode or in the frontend framework of your choice, and explain:
Constraints:
Input: comments=[{id:1,userId:2,timestamp:1000},{id:2,userId:1,timestamp:2000}], sortBy=timestamp, order=asc
Output: order=[id:1,id:2]
The first comment comes before the second because its timestamp, 1000, is earlier than 2000 and the requested direction is ascending.