Solution for Rosetta Code: Generator/Exponential

This will probably be my last one for a while, as I need to learn more in depth

What is your hint or solution suggestion?
How can you create an array of all squared numbers that is of a certain length? And how to filter out numbers for which x**(2/3) is not an integer before they are added to the array? Use Math.cbrt for a precise cube root.

Solution 1
function exponentialGenerator(n) {

  var firstNumbers=[];
  // Only change code below this line
  var i = 2;
  do {
    if(!Number.isInteger(Math.cbrt(i**2))){
      firstNumbers.push(i**2)
      }
    i++;
  }
  while (firstNumbers.length < n);

  return firstNumbers[n-1];
}

Challenge: Generator/Exponential

Link to the challenge:

curiosity, does it increase in precision if you first square the number, and then take the cube root?

1 Like

It didn’t, but I found that Math.cbrt returns the precise cube root. I fixed my code to reflect this

there was some miscommunication there, but your change is exactly what I meant!

1 Like

Thank you for your guide post contribution. I have taken your suggestions and included them in the guide post.

We look forward to your further contribution.