From 5ea8c6998df69297218613fd282c1f77b8492f71 Mon Sep 17 00:00:00 2001 From: Jizu Sun Date: Thu, 22 Nov 2018 09:30:27 +0800 Subject: [PATCH] katafy with the real power of `Generator.prototype.next()` - https://stackoverflow.com/a/37355045/3074866 --- katas/es6/language/generator/send-value.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/katas/es6/language/generator/send-value.js b/katas/es6/language/generator/send-value.js index d46a6bb7..185e46d1 100644 --- a/katas/es6/language/generator/send-value.js +++ b/katas/es6/language/generator/send-value.js @@ -17,21 +17,21 @@ describe('Pass a value to a generator', () => { assert.deepEqual(convertedToAnArray, iteratedOver); }); it('pass a value to the iterator', function() { - //// function* generatorFunction() { - function* generatorFunction(param) { - yield 1; - yield param; + function* generatorFunction() { + //// yield 1; + let value = yield 1; + yield value; } - //// var iterator = generatorFunction(); - var iterator = generatorFunction(2); + var iterator = generatorFunction(); var iteratedOver = [iterator.next().value, iterator.next(2).value]; assert.deepEqual([1, 2], iteratedOver); }); it('a value passed to the 1st `next()` call is ignored', function() { function* generatorFunction() { - yield 1; + //// yield 1; + let value = yield 1; //// - yield 2; + yield value; } let iterator = generatorFunction(); const values = [