detectCycle() {
        const obj = {};
        const result = [];

        for (let i = 0; i < globalScope.allNodes.length; i++) {
            const nodeId = globalScope.allNodes[i].id;
            for (let j = 0; j < globalScope.allNodes[i].connections.length; j++) {
                const connection = globalScope.allNodes[i].connections[j].id;
                if (obj[nodeId]) {
                    obj[nodeId].push(connection);
                } else {
                    obj[nodeId] = [connection];
                }
            }
        }

        const newNestedArray = [];
        const singleConnectionNodes = [];

        for (const node in obj) {
            const connections = obj[node];
            if (connections.length === 1) {
                singleConnectionNodes.push(node);
            }
            if (!isVisited(newNestedArray.flat(), node)) {
                const connectedNodes = [node];
                exploreNodes(obj, node, newNestedArray.flat(), connectedNodes);
                newNestedArray.push(connectedNodes);
            }
        }

        for (let i = 0; i < singleConnectionNodes.length - 1; i++) {
            for (let j = i + 1; j < singleConnectionNodes.length; j++) {
                if (areElementsInSameNode(newNestedArray, singleConnectionNodes[i], singleConnectionNodes[j])) {
                    const val1 = this.findNodeIndexById(singleConnectionNodes[i]);
                    const val2 = this.findNodeIndexById(singleConnectionNodes[j]);
                    if (globalScope.allNodes[val1].parent === globalScope.allNodes[val2].parent) {
                        result.push(dfs(obj, singleConnectionNodes[i], singleConnectionNodes[j]));
                    }
                }
            }
        }

        // Function to check whether a node is already visited
        function isVisited(visited, node) {
            return visited.includes(node);
        }

        // Function to explore interconnected nodes
        function exploreNodes(graph, startNode, visited, connectedNodes) {
            visited.push(startNode);
            if (graph[startNode]) {
                for (let i = 0; i < graph[startNode].length; i++) {
                    const connectedNode = graph[startNode][i];
                    if (!isVisited(visited, connectedNode)) {
                        connectedNodes.push(connectedNode);
                        exploreNodes(graph, connectedNode, visited, connectedNodes);
                    }
                }
            }
        }

        function areElementsInSameNode(nestedArray, element1, element2) {
            for (const node of nestedArray) {
                if (node.includes(element1) && node.includes(element2)) {
                    return true;
                }
            }
            return false;
        }

        // Function to locate the nodes present between two specified nodes
        function dfs(graph, start, end, path = []) {
            if (start === end) {
                path.push(end);
                return path;
            }
            path.push(start);
            for (const neighbor of graph[start]) {
                if (!path.includes(neighbor)) {
                    const newPath = dfs(graph, neighbor, end, path);
                    if (newPath) {
                        return newPath;
                    }
                }
            }
            path.pop();
            return [];
        }

        if (result.length) {
            this.highlightNodes(result);
            return result;
        }

        return 'No cycle found';
    }
Function to detect the nodes that are creating cyclic paths in the circuit