I think it is important to mention in the question that the array passed to the function has been dynamically created.
Hi Mahendra ,
This is Maida from Educative.
Thank you so much for your suggestion. We have incorporated your suggestion and updated the course with latest changes. I hope this is helpful.
We hope Educative has inspired to further your learning, and please drop us a note if you have any other questions or concerns.
Maida | Developer Advocate