I am doing this function in which a number is passed as a parameter; If it has any repeated digits, then it looks for the next largest number that does not have the same digits.
Ex:
proximoNumero(2002)
->return 2013
Ex:
proximoNumero(1001)
->return 1023
Ex:
proximoNumero(899)
->return 901
function proximoNumero(numero){
numero = (numero+1).toString().split('')
for(let i=0; i<numero.length-1; i++){
for(let j=i+1; j<numero.length; j++){
if(numero[i] === numero[j]){
console.log(`${numero} se repite ${numero[i]}`);
proximoNumero(Number(numero.join('')))
}
}
}
return numero.join('')
}
console.log(proximoNumero(1001));
my function is doing something similar but I don't understand why once it is called recursively with a number without repeated characters it returns the first number that is passed to it by parameter