educative.io

Exercise on Tail Call Optimization & other Function Features

In exercise 1 , I don’t understand why the len() function should be a getter?

Hi @Guy_Manevych !!
In Exercise 1, the len() function is designed as a getter because it allows you to access the length of the stack as a property (using stack.len), which is more intuitive and aligns with JavaScript’s standard practices like the length property of arrays. This approach enhances readability and encapsulation in the code.
I hope it helps. Happy Learning :blush: