Advertisement
rdsedmundo

take.net lookandsay

Jul 19th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lookandsay(x) {
  2.    var ans = "";
  3.  
  4.    var current = x[0], count = 1;
  5.  
  6.    for (var i = 1; i < x.length; i++)
  7.      if (x[i] == current)
  8.        count++;
  9.      else
  10.        ans += count.toString() + current, count = 1, current = x[i];
  11.  
  12.    ans += count.toString() + current;
  13.  
  14.    return ans;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement