// Given an array of words and a length L,
// format the text such that each line has exactly L characters and is fully (left and right) justified.

// You should pack your words in a greedy approach; that is, pack as many words as you can in each line.
// Pad extra spaces ' ' when necessary so that each line has exactly L characters.

// Extra spaces between words should be distributed as evenly as possible.
// If the number of spaces on a line do not divide evenly between words,
// the empty slots on the left will be assigned more spaces than the slots on the right.

// For the last line of text, it should be left justified and no extra space is inserted between words.

// For example,
// words: ["This", "is", "an", "example", "of", "text", "justification."]
// L: 16.

// Return the formatted lines as:
// [
//    "This    is    an",
//    "example  of text",
//    "justification.  "
// ]
// Note: Each word is guaranteed not to exceed L in length.

@@ -956,8 +956,992 @@
 length.%0A
+%0Avar fullJustify = function(words, maxWidth) %7B%0A    if( maxWidth%3C1 ) return %5B%22%22%5D;%0A    if( words.length %3C= 1 ) return %5BaddSpaces( maxWidth )%5D;%0A    var result = %5B%5D,%0A        currentRow = %22%22,%0A        rowLength = 0,%0A        currentWord,%0A        temp;%0A    for( var i=0; i%3Cwords.length; i++ )%7B%0A        currentWordLength = words%5Bi%5D.length;%0A        if( rowLength+currentWordLength %3C= maxWidth )%7B%0A            currentRow += words%5Bi%5D;%0A            rowLength += currentWordLength;%0A        %7D else %7B%0A            temp = maxWidth - rowLength;%0A            currentRow = addSpaces(temp) + currentRow;%0A            result.push(currentRow);%0A            currentRow = words%5Bi%5D;%0A            rowLength = words%5Bi%5D.length;%0A        %7D%0A    %7D%0A    if( !result%5Bresult.length-1%5D.includes( words%5Bwords.length-1%5D ) )%7B%0A        temp = maxWidth - rowLength;%0A        currentRow = addSpaces(temp) + currentRow;%0A        result.push( currentRow );%0A%0A    %7D%0A    return result;%0A%7D;%0A%0Afunction addSpaces( n )%7B%0A    return %22 %22.repeat(n);%0A%7D%0A

Add solution