cswork / libraryOpen practice workspace

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 ID
  • userId: author ID
  • timestamp: creation time
  • content: comment text
  • parentId: nullable parent comment ID

Implement the frontend behavior for a comment UI:

  1. Display comments sorted by either timestamp or userId.
  2. Support both ascending and descending order.
  3. Preserve the user's selected sort field and sort direction after a page refresh.
  4. Build nested comments from the flat input using parentId only; do not change the backend.
  5. Add a text filter on content so 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 →