perfect cycle in a list

    0

    0

    Ahmad Alhourani

    function test(arr,visited,index,counter,length ){
        
      if(length==0) return true;
        if(index>=length )return false;
        if(visited[index]){
            console.log('visited[index]counter',counter);
            console.log('visited[index]length',length);
            if(counter==length){
                return true;
            }
          else{
              return false;
          }
        }
        else{
          visited[index]=true;
          return test(arr,visited,arr[index],counter+1,length);
        }
        
      
    }
    
    
    let arr=[];//[0, 2 , 5];//[1, 2, 3];//[3,0,1,2];
    arr=[0, 2 , 5];
    arr=[1, 2, 3];
    arr=[3,0,1,2];
    
    let visited=[];
    let index=0;
    let counter=0;
    console.log("arr",arr);
    let length=arr.length;
    let res=test(arr,visited,index,counter,length)
    console.log("Welcome to Programiz!",res);
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.