> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/letcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/letcode/2-count-and-say-1/javascript-solution.md).

# javascript-solution

## 1.solution

```
var countAndSay = function(n) {
     res=""   
     oldAry = [];
                       oldAry.push(1)
                       ary = [];
                       ary.push(1)
                       round = 0;
                       count = 1;
                       index = 0;
                       len = 1;
                       while(round < n-1){
                         round++;
                         index = 0
                          for(i = 0 ; i < len; i++){
                            if (oldAry[i] === oldAry[i+1] )
                            {
                                  count++
                            }else{
                                  ary[index++] = count;
                                  ary[index++] = oldAry[i];
                                  count = 1;    
                            }
                         }
                         len = index ;
                         oldAry=ary.slice(0)
                       }
                       ary.forEach(function(element, index, array){
                           res+=element
                       })
                       return res
                      };
```

## 2.performance

![](https://github.com/jenhsuan/letcode/tree/4999a189073590294b35b42c8dfe17f9b5bebfad/assets/螢幕快照%202017-01-27%20上午10.53.35.png)
