Last active
November 14, 2022 14:11
-
-
Save alxpsr/b2f891fe234f0ff44353f8a5ad6e04a1 to your computer and use it in GitHub Desktop.
Revisions
-
alxpsr renamed this gist
Nov 14, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
alxpsr revised this gist
Nov 14, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,6 +32,6 @@ function forEachDeep<T extends INestable<T>>(array: T[], callback: (item: T) => forEachDeep(elem.nestedList, callback) } callback(item) }) } -
alxpsr created this gist
Nov 14, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ interface INestable<T> { nestedList?: T[]; } interface Item extends INestable<Item> { id: number; nestedList?: Item[]; } const recursiveStructure: Item[] = [ { id: 1, nestedList: [ { id: 11, }, { id: 22, nestedList: [ { id: 33, } ] } ] } ]; function forEachDeep<T extends INestable<T>>(array: T[], callback: (item: T) => void): void { array.forEach((elem: T) => { if (elem.nestedList) { forEachDeep(elem.nestedList, callback) } callback }) }