Write two generators: walk an array in circular jumps, and yield factorials as BigInt
Problem
Generators can pause, hand back a value, and receive one on the way back in. Write two of them.
const gen = circular([10, 20, 30, 40, 50], 0);
gen.next().value; // 10
gen.next(1).value; // 20
gen.next(2).value; // 40
gen.next(-3).value; // 10
gen.next(7).value; // 30 (7 steps from index 0 lands on index 2)Ref. UR-1424 · © UIRound · uiround.com/questions/write-two-generators-walk-an-array-in-circular-jumps-and-yield-factorials-as-bigint
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 2
- code listings
- 5
- edge cases
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1A value passed to next(value) becomes the result of the yield expression that paused the generator. The very first next() starts the generator and its argument is thrown away.
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.