Skip to content

Instantly share code, notes, and snippets.

@DavidJRobertson
Last active December 13, 2015 21:58
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 DavidJRobertson/4981261 to your computer and use it in GitHub Desktop.
Save DavidJRobertson/4981261 to your computer and use it in GitHub Desktop.
function separateLines (input, chars) {
var lines = [];
while (input.length > chars) {
var text = input.substr(0, chars);
var i = text.lastIndexOf(" ");
if (i == -1) {
i = chars - 1;
}
lines.push(text.substr(0, i));
input = input.substr(i + 1);
}
if (input.length > 0) {
lines.push(input);
}
return lines;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment