(list, key = 'children')
| 1 | // ---------------------------------------------------------------------- |
| 2 | |
| 3 | export default function flattenArray(list, key = 'children') { |
| 4 | let children = []; |
| 5 | |
| 6 | const flatten = list?.map((item) => { |
| 7 | if (item[key] && item[key].length) { |
| 8 | children = [...children, ...item[key]]; |
| 9 | } |
| 10 | return item; |
| 11 | }); |
| 12 | |
| 13 | return flatten?.concat(children.length ? flattenArray(children, key) : children); |
| 14 | } |
nothing calls this directly
no outgoing calls
no test coverage detected