The attached code is what the entire method would look like all together.

The time complexity would be O(n) or linear time.

JAVASCRIPT
OUTPUT
Results will appear here.