Interview questions · Bobyard
Implement comment sorting and nesting
This question evaluates skills in frontend data handling and UI behavior, including implementing sortable lists, maintaining user-selected sort field and direction across refreshes, constructing nested comment trees from flat parentId references, and filtering content while preserving descendant visibility.
You are given mock comment data on the frontend. Each comment has:
id: unique comment IDuserId: author IDtimestamp: creation timecontent: comment textparentId: nullable parent comment ID
Implement the frontend behavior for a comment UI:
- Display comments sorted by either
timestamporuserId. - Support both ascending and descending order.
- Preserve the user's selected sort field and sort direction after a page refresh.
- Build nested comments from the flat input using
parentIdonly; do not change the backend. - Add a text filter on
contentso that only comments matching the filter and all of their descendants are shown. Unrelated branches must be hidden.
You may assume the data is provided locally as mock data.
Community answers
Nothing here yet.
Join in on CSWork →