Skip to content

Instantly share code, notes, and snippets.

@nick-jonas
Created March 5, 2013 17:18
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 nick-jonas/5092017 to your computer and use it in GitHub Desktop.
Save nick-jonas/5092017 to your computer and use it in GitHub Desktop.
Add   between last two words in a body of text to avoid orphans.
var orig = 'My sample body text',
split = orig.split(' '),
lastTwo = split.splice(split.length - 2);
lastTwo = lastTwo.join(' ');
split = split.join(' ') + ' ' + lastTwo;
orig = split;
// orig = 'My sample body text'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment