Hey I am working in kotlin. I want to find index i...
# android
v
Hey I am working in kotlin. I want to find index in which the variable value is true. I used MapIndex to find index of that value which is true. But I am using nesting mapIndex so may be there time complexity would be multiple. I need to improve that mapIndex logic to be more efficient in performance, speed, memory etc.
Copy code
private fun getNodeDefaultValuePosition() {
        baseNode.children.mapIndexed { strengthIndex, strengthVariantNode ->
            if ((strengthVariantNode as StrengthNode).defaultValue.get()) {
                strengthSearchIndex = strengthIndex
            }
            strengthVariantNode.children.mapIndexed { quantityIndex, quantityVariantNode ->
                if ((quantityVariantNode as QuantityNode).defaultValue.get()) {
                    quantitySearchIndex = quantityIndex
                }
                quantityVariantNode.children.mapIndexed { index, variantNode ->
                    if ((variantNode as SubscriptionNode).defaultValue.get()) {
                        subsriptionSearchIndex = index
                    }
                }
            }
        }
    }
How can I avoid use of nested MapIndex. Any idea for improving the logic. My whole Project Link