Title: removeEmptyFloder · Issue #3 · LSP-XA/fe-Involution · GitHub
Open Graph Title: removeEmptyFloder · Issue #3 · LSP-XA/fe-Involution
X Title: removeEmptyFloder · Issue #3 · LSP-XA/fe-Involution
Description: let Arr = [ { name: "1", type: "floder", children: [{ name: "1", type: "file" }] }, { name: "2", type: "floder", children: [ { name: "1", type: "floder", children: [ { name: "1", type: "floder", children: [{ name: "1", type: "floder", ch...
Open Graph Description: let Arr = [ { name: "1", type: "floder", children: [{ name: "1", type: "file" }] }, { name: "2", type: "floder", children: [ { name: "1", type: "floder", children: [ { name: "1", type: "floder", ch...
X Description: let Arr = [ { name: "1", type: "floder", children: [{ name: "1", type: "file" }] }, { name: "2", type: "floder", children: [ { name: &quo...
Opengraph URL: https://github.com/LSP-XA/fe-Involution/issues/3
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"removeEmptyFloder","articleBody":"```js\r\nlet Arr = [\r\n { name: \"1\", type: \"floder\", children: [{ name: \"1\", type: \"file\" }] },\r\n {\r\n name: \"2\",\r\n type: \"floder\",\r\n children: [\r\n {\r\n name: \"1\",\r\n type: \"floder\",\r\n children: [\r\n {\r\n name: \"1\",\r\n type: \"floder\",\r\n children: [{ name: \"1\", type: \"floder\", children: [] }],\r\n },\r\n ],\r\n },\r\n ],\r\n },\r\n {\r\n name: \"3\",\r\n type: \"floder\",\r\n children: [\r\n {\r\n name: \"1\",\r\n type: \"floder\",\r\n children: [{ name: \"1\", type: \"floder\", children: [] }],\r\n },\r\n ],\r\n },\r\n];\r\n\r\nfunction removeEmptyFloder(arr) {\r\n const emptyFloder = []\r\n const root = {\r\n children: arr,\r\n }\r\n\r\n function walkTree(tree = [], parent) {\r\n for (let node of tree) {\r\n node.parent = parent\r\n if (node.children \u0026\u0026 node.children.length) {\r\n walkTree(node.children, node)\r\n }\r\n // mark empty floder\r\n if (node.type === 'floder') {\r\n if (!node.children || node.children.length === 0) {\r\n emptyFloder.push(node)\r\n }\r\n }\r\n }\r\n }\r\n\r\n walkTree(arr, root)\r\n\r\n function removeSelf(node) {\r\n if (node.parent) {\r\n node.parent.children = node.parent.children.filter(item =\u003e item !== node)\r\n if (node.parent.children.length === 0) {\r\n removeSelf(node.parent)\r\n }\r\n }\r\n }\r\n\r\n emptyFloder.forEach(removeSelf)\r\n\r\n return JSON.parse(JSON.stringify(root.children, (key, value) =\u003e key === 'parent' ? undefined : value))\r\n}\r\n```","author":{"url":"https://github.com/jdz321","@type":"Person","name":"jdz321"},"datePublished":"2021-06-25T08:15:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/3/fe-Involution/issues/3"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d1bab8d9-9a5a-5208-0562-bdb7793d61d7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C9C6:8E554:1BC8DB9:24BD627:698D7F63 |
| html-safe-nonce | 9c907e3a8c47890caa6ebbdaa9f32e35131bf5404ecc828d8b59a6daaed153ee |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUM2OjhFNTU0OjFCQzhEQjk6MjRCRDYyNzo2OThEN0Y2MyIsInZpc2l0b3JfaWQiOiI0Mzk1OTU1ODQzMDU0MjcyMzU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 45d8a88f1009cafa0f5ce4409f96c8eca11a5dfd4b66bf01c2cdfeebde8ce65f |
| hovercard-subject-tag | issue:929948073 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/LSP-XA/fe-Involution/3/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3957c5452ef408cb0c57ac2337a3f39f62811b09605c2cf1997e86188f623519/LSP-XA/fe-Involution/issues/3 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3957c5452ef408cb0c57ac2337a3f39f62811b09605c2cf1997e86188f623519/LSP-XA/fe-Involution/issues/3 |
| og:image:alt | let Arr = [ { name: "1", type: "floder", children: [{ name: "1", type: "file" }] }, { name: "2", type: "floder", children: [ { name: "1", type: "floder", children: [ { name: "1", type: "floder", ch... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jdz321 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c0818105fa276287e9369cfdefa0a0fa7953719791ceff9b94d69623c0a4fe8a |
| turbo-cache-control | no-preview |
| go-import | github.com/LSP-XA/fe-Involution git https://github.com/LSP-XA/fe-Involution.git |
| octolytics-dimension-user_id | 76473284 |
| octolytics-dimension-user_login | LSP-XA |
| octolytics-dimension-repository_id | 360762000 |
| octolytics-dimension-repository_nwo | LSP-XA/fe-Involution |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 360762000 |
| octolytics-dimension-repository_network_root_nwo | LSP-XA/fe-Involution |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 715890fa442134f528fb422ab338c0ad55c7a025 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width