Last active
March 4, 2019 04:04
-
-
Save Maccauhuru/265ca5ef32ec8f84e8078ee8e322078a to your computer and use it in GitHub Desktop.
Function Generator Example 2
This file contains 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
//Create a generator function to display some popular JS frameworks/libraries | |
function* displayFrameworks(){ | |
const javascriptFrameworks = ['Angular','React','Vue']; | |
for(let i=0;i < javascriptFrameworks.length;i++){ | |
yield javascriptFrameworks[i]; | |
} | |
} | |
const listFW = displayFrameworks(); // Generator { } | |
//Output each element of the array to console | |
console.log(`${listFW.next().value} is very popular in the JS ecosystem`); | |
//->Angular is very popular in the JS ecosystem | |
console.log(`${listFW.next().value} is very popular in the JS ecosystem`); | |
//->React is very popular in the JS ecosystem | |
console.log(`${listFW.next().value} is very popular in the JS ecosystem`); | |
//->Vue is very popular in the JS ecosystem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment