Skip to content

Instantly share code, notes, and snippets.

@Maccauhuru
Last active March 4, 2019 04:04
Show Gist options
  • Save Maccauhuru/265ca5ef32ec8f84e8078ee8e322078a to your computer and use it in GitHub Desktop.
Save Maccauhuru/265ca5ef32ec8f84e8078ee8e322078a to your computer and use it in GitHub Desktop.
Function Generator Example 2
//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