0

I have a dictionary, I want to count how many times recursion functions run.

AddConditoinalSection (input_def ) {

    input_def.id = this.uid()

    var ConditionalDiv

    for (var i in input_def.cases) {

        ConditionalDiv  = document.createElement('div')
        ConditionalDiv.className = 'ui-form-element section-row pl-2'
        ConditionalDiv.id = `${input_def.id}-section-${i}`
    
        for (var j in input_def.cases[i].inputs ) {

            if (input_def.cases[i].inputs[j].type !== 'conditional') {

                input_def.cases[i].inputs[j].id = this.uid()
                const SimpleRow  = document.createElement('div')
                SimpleRow.className = 'ui-form-element section-row' 
                SimpleRow.id = input_def.cases[i].inputs[j].id
                ConditionalDiv.append(SimpleRow)
                
            } 

            else{ 

                input_def.cases[i].inputs[j].id = this.uid()
                this.AddConditoinalSection(input_def.cases[i].inputs[j])
            }
        }

        this.element.querySelector('.Dynamic-form').append(ConditionalDiv)
    }
 }  

Input_def could have cases and each case has its own input_def, again input def could have cases. I want to know how many times it encounters a conditional block recursively.

jax
  • 3,927
  • 7
  • 41
  • 70
  • 3
    Just add a `depth` counter to your function parameters, and increment it by 1 for each recursive call. – Bergi Jul 05 '21 at 02:02
  • @Bergi Thanks, I am trying to solve this problem do you have any comments on this question? https://stackoverflow.com/questions/68217583/how-to-append-dynamically-generated-recursive-sections-of-dom-elements-to-its-pa – jax Jul 05 '21 at 02:08
  • There is no recursion here: your function name is different (2, 3?) – trincot Jul 05 '21 at 07:30
  • Does this answer your question? [Keep track of how many times a recursive function was called](https://stackoverflow.com/questions/59570841/keep-track-of-how-many-times-a-recursive-function-was-called) – customcommander Jul 05 '21 at 07:44

0 Answers0