/*here is the algorithm for now
-create an emtpy array (Arr) that will contain the lines of the output (output) from the input string (Sn). A line will be an element of Arr.
-make sure that the Sn does not start or end with a space. If so, trim it.
-get a count of the number of characters (including spaces) there are in Sn.
-parse a substring (S1) from the beginning of Sn that is the length of the allowed line length.
-check to see if the S1 ends in a space. If so, trim S1 end space.
--find the first space (s_first_S1) in S1 (that will be between the first and second word) and add a space to s_1. S1 is the first line.
-else if S1 does not in a space does the 2nd substring (S2) of Sn start with a space?
--if so, the S1 is a full line that breaks at the end of the last word.
--else if inputString (the remaining input string after parsing S1 out) does not begin with a space then you have ended S1 in the middle of a word.
---find the last space (s_last_S1) in S1. From that position, count the number of characters to the end of S1 (Cn_end_S1).
---trim the end of S1 by Cn_end_S1 characters (this should remove the space as well from the end of S1).
---for each space in S1, take number in Cn_end_S1 and add a space to each space in S1 starting at the beginning of S1 to the end of S1. Continue this process until Cn_end_S1 is = 0. This should meet the rule, Large gaps go first, then smaller: 'Lorem---ipsum---dolor--sit--amet' (3, 3, 2, 2 spaces).
-take the length of S1 and parse it from the beginning of Sn and use the remainder of Sn to create a new Sn, replacing the old Sn.
-now add "\n" to the S1
-add S1 as a new element to Arr.
-start over again with the new Sn (inputString)
*/
MyJustify = function () {};
var outputArr = [];
MyJustify.prototype.createParagraph = function (inputString, numberOfCharsPerLine) {
//create an emtpy array (Arr) that will contain the lines of the output (output) from the input string (Sn). A line will be an element of Arr.
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.