Skip to content

Instantly share code, notes, and snippets.

@tormaroe
Created February 13, 2019 14:37
Show Gist options
  • Save tormaroe/8413d02ebeb1b11b4e3f296618fc5683 to your computer and use it in GitHub Desktop.
Save tormaroe/8413d02ebeb1b11b4e3f296618fc5683 to your computer and use it in GitHub Desktop.
Example code JS
function wrap (text, limit) {
if (text.length > limit) {
// find the last space within limit
var edge = text.slice(0, limit).lastIndexOf(' ');
if (edge > 0) {
var line = text.slice(0, edge);
var remainder = text.slice(edge + 1);
return line + '\n' + wrap(remainder, limit);
}
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment