Could you elaborate on "Recursive functions are a great substitute of while loops for the tasks like traversing when we don't know the size of the list before we start iterating."?
I don't see what prior knowledge of the list size has to do with substituting while loop for a recursive call.
Traverse method could be easily implemented with while loop and it has an advantage of not worrying about exceeding a call stack.
Also traverse method is a good candidate for using a technique called "tail recursion", but for JavaScript tail call is currently supported only by Safari/WebKit.
Hey Mateusz, thanks for your feedback! Probably, the sentence is not very well structured. What I meant is that in the traverse example we donβt have prior knowledge of the size and therefore we cannot use for loops. However we can use a while loop or alternatively a recursive function.
Itβs a great input regarding the call stack overflow πππ, I definitely missed it out of sight, since I alway tend to be biased toward functional approaches.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Gleb, nice and clear article :)
Could you elaborate on "Recursive functions are a great substitute of while loops for the tasks like traversing when we don't know the size of the list before we start iterating."?
I don't see what prior knowledge of the list size has to do with substituting while loop for a recursive call.
Traverse method could be easily implemented with while loop and it has an advantage of not worrying about exceeding a call stack.
Also traverse method is a good candidate for using a technique called "tail recursion", but for JavaScript tail call is currently supported only by Safari/WebKit.
Hey Mateusz, thanks for your feedback! Probably, the sentence is not very well structured. What I meant is that in the traverse example we donβt have prior knowledge of the size and therefore we cannot use for loops. However we can use a while loop or alternatively a recursive function.
Itβs a great input regarding the call stack overflow πππ, I definitely missed it out of sight, since I alway tend to be biased toward functional approaches.