src/utils/deepClone.js
function isCyclic (data) {
    
    // Create an array that will store the nodes of the array that have already been iterated over
    let seenObjects = [];

    function detect (data) {
        // If the data pass is an object
        if (data && getType(data) === "Object") {
            
            // If the data is already in the seen nodes array then we know there is a circular reference
            // Therefore return true
            if (seenObjects.indexOf(data) !== -1) {
                return true;
            }

            // Add the data to the seen objects array
            seenObjects.push(data);

            // Begin iterating through the data passed to the method
            for (var key in data) {
                // Recall this method with the objects key
                if (data.hasOwnProperty(key) === true && detect(data[key])) {
                    return true;
                }
            }
        }
        return false;
    }

    // Return the method
    return detect(data);
}
function isCyclic (data) {
    
    // Create an array that will store the nodes of the array that have already been iterated over
    let seenObjects = [];

    function detect (data) {
        // If the data pass is an object
        if (data && getType(data) === "Object") {
            
            // If the data is already in the seen nodes array then we know there is a circular reference
            // Therefore return true
            if (seenObjects.indexOf(data) !== -1) {
                return true;
            }

            // Add the data to the seen objects array
            seenObjects.push(data);

            // Begin iterating through the data passed to the method
            for (var key in data) {
                // Recall this method with the objects key
                if (data.hasOwnProperty(key) === true && detect(data[key])) {
                    return true;
                }
            }
        }
        return false;
    }

    // Return the method
    return detect(data);
}
function isCyclic ( data ) { // Create an array that will store the nodes of the array that have already been iterated over let seenObjects = [ ] ; function detect ( data ) { // If the data pass is an object if ( data && getType ( data ) === "Object" ) { // If the data is already in the seen nodes array then we know there is a circular reference // Therefore return true if ( seenObjects . indexOf ( data ) !== - 1 ) { return true ; } // Add the data to the seen objects array seenObjects . push ( data ) ; // Begin iterating through the data passed to the method for ( var key in data ) { // Recall this method with the objects key if ( data . hasOwnProperty ( key ) === true && detect ( data [ key ] ) ) { return true ; } } } return false ; } // Return the method return detect ( data ) ; }
Create a method to detect whether an object contains a circular reference
Create a method to detect whether an object contains a circular reference