```
var countAndSay = function(n) {
let s = ['1'];
let i = 0;
while (i < n - 1) {
for (let j = 0; j < s[i].length; j++) {
let c = s[i][j];
let k = 1;
while (s[i][j + 1] === c) {
j++;
k++;
}
if (s[i + 1]) s[i + 1] += k + '' + c;
else s[i + 1] = k + '' + c;
}
i++;
}
return s[n - 1];
};
```