Created
January 19, 2018 17:19
-
-
Save RinatValiullov/555b20f6751c82768c5ccee9f42ab76f to your computer and use it in GitHub Desktop.
Create array with generated random values (iterator)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let randoms = { | |
[Symbol.iterator]: function() { | |
return { | |
next: function() { | |
// Generate values in range [0..10] | |
return { value: Math.round(Math.random() * 10) }; | |
} | |
}; | |
} | |
}; | |
let random_arr = []; | |
for (let elem of randoms) { | |
random_arr.push( elem ); | |
// Generate 10 elements | |
if (random_arr.length === 10) break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment