Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. var fullJustify = function(words, maxWidth) {
  2. var lines = [];
  3. var currentLineWords = [];
  4. var currentLine = '';
  5.  
  6. words.forEach((word) => {
  7. for (let letter of word) {
  8. // add one to counter for each letter
  9. currentLine += letter;
  10.  
  11. }
  12. if((currentLine.length + word.length) <= maxWidth) {
  13. // add one to counter for each word to account for a minimum space of 1
  14. currentLine += " ";
  15. currentLineWords.push(word)
  16. } else {
  17. lines.push(currentLineWords);
  18. currentLineWords = [];
  19. currentLineWords.push(word)
  20. currentLine = "";
  21. }
  22. if(words.indexOf(word) == words.length - 1) {
  23. lines.push(currentLine.split(" "));
  24. }
  25. console.log(currentLine)
  26. console.log(currentLineWords)
  27. console.log(lines)
  28. });
  29. return lines;
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement