Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fullJustify = function(words, maxWidth) {
- var lines = [];
- var currentLineWords = [];
- var currentLine = '';
- words.forEach((word) => {
- for (let letter of word) {
- // add one to counter for each letter
- currentLine += letter;
- }
- if((currentLine.length + word.length) <= maxWidth) {
- // add one to counter for each word to account for a minimum space of 1
- currentLine += " ";
- currentLineWords.push(word)
- } else {
- lines.push(currentLineWords);
- currentLineWords = [];
- currentLineWords.push(word)
- currentLine = "";
- }
- if(words.indexOf(word) == words.length - 1) {
- lines.push(currentLine.split(" "));
- }
- console.log(currentLine)
- console.log(currentLineWords)
- console.log(lines)
- });
- return lines;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement