Write a function that converts an array of objects arr into a matrix m.
arr is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.
The first row m[0] should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by ".".
Each of the remaining rows corresponds to an object in arr. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string "".
The columns in the matrix should be in lexicographically ascending order.
Input & Output
Constraints
- 1 ≤ arr.length ≤ 1000
- Each object can be nested up to 1000 levels deep
- Column names will be valid strings
- Values can be null, boolean, number, or string