Question Bank

Object Transformation Challenges

Difficulty: Medium

Six object-shape problems: building a tree from a flat array, valid-key extraction, chainable methods, stats reshaping, recursive leaf walking, and deep equality.

Question Bank
/

Object Transformation Challenges

Object Transformation Challenges

Six object-shape problems: building a tree from a flat array, valid-key extraction, chainable methods, stats reshaping, recursive leaf walking, and deep equality.

Question Bank
Medium
JavaScript
6 questions
quiz
references
js-spread-rest
interview-prep

575 views

2

Implement transformData(data) that turns a flat list of { id, name, parentFeatureId, level } into a map keyed by top-level feature name, each holding { parent, features: [...children] }.

Examples

Example 1:

Input: transformData([{ id: 1, name: 'Feature#A', parentFeatureId: 0, level: 1 }, { id: 2, name: 'Feature#A-1', parentFeatureId: 1, level: 2 }])
Output: { 'Feature#A': { parent: { id: 1, ... }, features: [{ id: 2, ... }] } }
Explanation: Pick parents (parentFeatureId === 0), then group children by their parent id.