( choices: IChoice[], parentId: string, child: IChoice, )
| 986 | } |
| 987 | |
| 988 | function insertUnderParent( |
| 989 | choices: IChoice[], |
| 990 | parentId: string, |
| 991 | child: IChoice, |
| 992 | ): boolean { |
| 993 | for (const choice of choices) { |
| 994 | if (choice.id === parentId && choice.type === "Multi") { |
| 995 | insertIntoMulti(choice as IMultiChoice, child); |
| 996 | return true; |
| 997 | } |
| 998 | if (choice.type === "Multi") { |
| 999 | const multi = choice as IMultiChoice; |
| 1000 | if (multi.choices && insertUnderParent(multi.choices, parentId, child)) { |
| 1001 | return true; |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | function insertIntoMulti(parent: IMultiChoice, child: IChoice): void { |
| 1009 | if (!Array.isArray(parent.choices)) { |
no test coverage detected