Skip to content
Advertisement

How can I use Yield and Range to get the position and item from a list?

I’d like to implement yield and range to challenge myself and get a better understanding of both. I’m trying to use yield to loop through a function to get a random number within the list. And range used somewhere within as well. The current function below I have isn’t currently working.

JavaScript

Advertisement

Answer

The following may hint you at what’s going on:

JavaScript

A less wasteful implementation:

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