fork download
  1. function sequence(start, step) {
  2. var x = 0;
  3. return function () {
  4. start = start || 0;
  5. step = step || 1;
  6. var y = start + (step * x)
  7. x++;
  8. return y;
  9. }
  10. }
  11.  
  12.  
  13. function take(gen, x) {
  14. var arr = [];
  15. for (var i = 0; i < x; i++) {
  16. arr[i] = gen();
  17. };
  18. return arr;
  19. }
  20.  
  21.  
  22.  
  23. var gen2 = sequence(0, 2);
  24. console.log(take(gen2, 5)); // [0, 2, 4, 6, 8 ]
Runtime error #stdin #stdout #stderr 0.49s 321920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "console" is not defined.