Lesson 112 | Basic JavaScript | Use Recursion to Create a Countdown

preview_player
Показать описание
Good to have you here!

Jasmyne

#freecodecamp #javascript #softwareengineer #facebook #google #gitstart
#programming
Рекомендации по теме
Комментарии
Автор

Why is it in the previous Recursion lesson, "Replace Loops With Recursion" when you put in the first parameter n for
return multiply(arr, n -1) * arr[n-1];
the first n input value didn't save, for example, lets say n = 5:
return multiply(arr, 5 -1) * arr[n-1];
is actually: return multiply(arr, 4) * arr[4];
and not: return multiply(arr, 5) * arr[5];
but in this lesson when you put in the first parameter, which is n = 5, the first parameter is saved and used, countdown(5), even though it is countdown(n-1). Shouldn't it start at countdown(4) like the previous recursion lesson?

davidzenteno
Автор

Why number is decreasing is understandable, it is because of n - 1.
But why is value of n increasing after reaching zero when it is inside the array?

rahultickoo
welcome to shbcf.ru