MCPcopy Create free account
hub / github.com/codingmonk-yt/chat-app-latest / flattenArray

Function flattenArray

src/utils/flattenArray.js:3–14  ·  view source on GitHub ↗
(list, key = 'children')

Source from the content-addressed store, hash-verified

1// ----------------------------------------------------------------------
2
3export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected