Skip to content

Instantly share code, notes, and snippets.

@davidsm
Last active April 29, 2016 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsm/f4f4634b1ce249198b9bd9b3812c53f3 to your computer and use it in GitHub Desktop.
Save davidsm/f4f4634b1ce249198b9bd9b3812c53f3 to your computer and use it in GitHub Desktop.
function counterstring(length) {
var curNum = length;
var outLen = 0;
var numbers = [];
var curStr;
while (outLen < length) {
curStr = curNum.toString() + "*";
curNum -= curStr.length;
if (outLen + curStr.length <= length) {
numbers.push(curStr);
outLen += curStr.length;
}
else {
numbers.push("*");
break;
}
}
return numbers.reverse().join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment