Skip to content

Instantly share code, notes, and snippets.

@davidsm
Last active Apr 29, 2016
Embed
What would you like to do?
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