Problem description:

> 
> There is a string, `s`, of lowercase English letters that is repeated infinitely many times. Given an integer, `n`, find and print the number of letter `a`'s in the first `n` letters of the infinite string.
> 
> 
> 

I had a function that works and passes the test in hacker rank, but the only test that I have an issue with is that it runs out of memory. I thought it would be from the while loop, but I don't understand where the issue is coming from.

**Error:**

```
semi-space copy Allocation failed - JavaScript heap out of memory

```

**repeatedString.js:**

```js
// Repeated String
function repeatedString(s, n) {
  // WRITE YOUR CODE HERE
  let infiniteString = s;

  // String Length (Too Small)
  if (infiniteString.length < n) {
    while (infiniteString.length < n) {
      infiniteString += s;
    }
  }

  // Frequency Count
  let frequencyCount = 0;

  // Iterate Over String
  for (let i = 0; i < n; i++) {
    if (infiniteString[i] === 'a') {
      frequencyCount += 1;
    }
  }

  return frequencyCount;
};

```