Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Mirror Inverse Program in javascript

<script>
 
// JavaScript implementation of the approach
 
 
    // Function that returns true if
    // the array is mirror-inverse
    function isMirrorInverse(arr) {
        for (i = 0; i < arr.length; i++) {
 
            // If condition fails for any element
            if (arr[arr[i]] != i)
                return false;
        }
 
        // Given array is mirror-inverse
        return true;
    }
 
    // Driver code
     
        var arr = [ 1, 2, 3, 0 ];
        if (isMirrorInverse(arr))
            document.write("Yes");
        else
            document.write("No");
 
// This code contributed by Rajput-Ji
 
</script>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Mirror #Inverse #Program #javascript
ADD COMMENT
Topic
Name
2+3 =