Created
February 13, 2019 14:37
-
-
Save tormaroe/8413d02ebeb1b11b4e3f296618fc5683 to your computer and use it in GitHub Desktop.
Example code JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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