# 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/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202017-01-27%20%E4%B8%8A%E5%8D%8810.53.35.png)
