Why do I get regeneratorRuntime is not defined?

Why do I get regeneratorRuntime is not defined?
0

#1

Hi

Why do I get a “regeneratorRuntime is not defined” error while attempting the Project Euler Primes Summation problem? I used the javascript form of this recipe. As you can see I have used a generator function.

What am I doing wrong?

The code:

function primeSummation(n) {
    var nxt=0, sum=0, ps=erat();
    for (let nxt of ps) {
        if (nxt<n) {sum+=nxt;}
        else {break;}
    }
    return sum;

    function* erat() {
        var D={}, q=2;
        while (true) {
            p=D[q]; delete D[q];
            if (p) {
                x=p+q;
                while (x in D) {x+=p}
                D[x]=p;
            }
            else {
                D[q*q]=q;
                yield q;
            }
            q+=1;
        }
    }
}


#2

post your code first where you stuck


#3

Posted the code. This code runs fine in my local node command prompt.

Update!!
Tried Euler Problem 12 just now with a generator function. I get the same feedback: regeneratorRuntime is not defined


#4

Hello Amaity,

I got the reason behind the error

  1. In Babel (ES6) not support this code it’s get following error
Uncaught ReferenceError: regeneratorRuntime is not defined
  1. In LiveScript also get and error Becuase of i think not support syntax.
compileError: Parse error on line 1: Unexpected 'CALL('

3.In CoffeeScript also get error because of the function is Reserved word.

compileError: reserved word "function"
  1. TypeScript not getting error but output looks like folllowing.
0
  1. In JavaScript the get the right output In pass the Value 10 then gets
17

Hope this helpful.


#5

Hello amaity,
The reason is the getting error is as following Language support

  1. Normal Js their is no error you get Right output.
Input 10 the output gets 17 
  1. In Babel (ES6) the you get an error (not supoorted)
Uncaught ReferenceError: regeneratorRuntime is not defined

3.In TypeScript get output as follows

0
  1. In CoffeeScript get error
compileError: reserved word "function"

5.In LiveScript

compileError: Parse error on line 1: Unexpected 'CALL('

Hope this helpful for you.


#6

Thanks for spending time to run through the code.

So is this because of my browser( Chrome ) ?? Or is this error so basic that no finds this interesting??

What do the experts say ???


#7

Afaik, to run the tests the FCC server is attempting to transpile your code from es6 (eg convert the code from the current version of the language to an earlier version) using a tool called Babel. To work, Babel uses a series of plugins. The plug-in to convert es6 generators is large and produces very slow code, so is generally not included with Babel setups unless absolutely necessary. If it isn’t included, and you try to run code with a generator through Babel and the above is true, then you get the error message you’re seeing.

It’s nothing to do with Chrome, any other browser, etc. Generators work just fine almost everywhere now. Afaics it means something needs fixing on the FCC side


#8

Thanks @DanCouper.

To get over this problem I converted the generator into a normal function like so:

function primeSummation(n) {
    var sum=0, D={}, q=2;
    while (q<n) {
        var p=D[q]; delete D[q];
        if (p) {
            var x=p+q;
            while (x in D) {x+=p}
            D[x]=p;
        }
        else {
            D[q*q]=q;
            sum+=q;
        }
        q+=1;
    }
    return sum;
}

Though this is slightly slower, it still give me the answers in a few seconds. But FCC gives me the following:

// running test
primeSummation(140759) should return 873608362.
primeSummation(2000000) should return 142913828922.
// tests completed

NOW is this a Server-end problem or is the code the problem ???


#9

What does your code return for those functions? If its the same as the tests there’s something wrong with your code. If it isn’t then then it’s too slow and it’s timing out, or its detected that there is a possible infinite loop and has errored. If it’s the latter, look at the console, there should be an error with a line number. Add // noprotect above the line it states.

Edit: missed that. A few seconds is a long time, the tests are timing out.


#10

Thanks @DanCouper.

Am I the only guy having this problem? I tried a copy book sieve algorithm from the wiki and I still get the following :

// running test
primeSummation(2000000) should return 142913828922.
// tests completed

It doesn’t pass the last test.
Funny, no one seems to have complained about this problem yet :tired_face:
So what is the right way to attack these problems in FCC ???