Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Created March 17, 2021 04:07
Show Gist options
  • Save ashwinkumar2438/7a06420ca8568a3cbfbd59f6f68ec2f6 to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/7a06420ca8568a3cbfbd59f6f68ec2f6 to your computer and use it in GitHub Desktop.
function* addGen(sum){
let first= yield sum;
sum+=first;
let second=yield sum;
sum+=second;
return sum;
}
let addwith=addGen(40);
console.log(addwith.next()); //@yields {value: 40, done: false}
console.log(addwith.next(40)); //@yields {value: 80, done: false}
console.log(addwith.next(20)); //@returns {value: 100, done: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment