Skip to content
Advertisement

Stack forEach expression to loop for difference between existing size and new one [closed]

I have a class with data member:

JavaScript

The idea was to see if this forms a use case for lambda functions. But it will not allow me as it is expecting a boolean in place of diff. Is lambda forEach a use-case here?

Advertisement

Answer

Since Stack extends Vector, if you wanted to increase the capacity, then you could have used ensureCapacity (in Vector)

JavaScript

If you wanted to do myStack.push("something") diff times, then you could have used:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement