mardi 17 décembre 2019

if statement with recursive function angular

I am a beginner, I am blocked, I have a test which calls for a recursive function, after the execution of this function and according to its return value we do processing, the function return true, after return false even if the condition is valid, it stays in loop true false, true false.I am trying but need help, can anyone point me in the right direction please.

if (ROUTES.length !== 0) {
  if(this.Validate(ROUTES)){
     return true;
  } 
  else {
    this.location.back();
  }
}


Validate(list: Route[]) {    
  let path:boolean;
  for (let x of list) {
    if (this.router.url === x.path) {
      path = true;
    } else if (x.menu.length !== 0) {
      return this.Validates(x.menu);
    } else
      path = false;
  }

  return path;

}

Aucun commentaire:

Enregistrer un commentaire