We can alternatively use an iterative approach.

JAVASCRIPT
OUTPUT
Results will appear here.