Bu snippet'i her çalıştırdığımda, dönüşten önce konsol.log, değeri 23 katın 20 katı ile döndürür. Ancak, console.log (Check (users, 0, 20)); sadece 'undefined' değerini döndürür.Özyinelemeli işlevin dönüş değeri 'undefined'
Neyi yanlış yapıyorum?
var users = [23, 23, 23, 23, 23, 23, 23, 23, 23, 23];
console.log(Check(users, 0, 20));
function Check(ids, counter, limit){
ids.push(23);
// Recursion
if (counter+1 < limit){
Check(ids, counter+1, limit);
}
else {
console.log(ids);
return ids;
}
}
'if' bloğunda' return' ifadesi 'undefined' anlamına gelir. Eğer fonksiyonun sonuna bir '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ifadesine getirin ve değeri if if' ifadesi – Ian