Advertisement
Pijomir

Format The Text

Jan 24th, 2024 (edited)
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let outputRef = document.getElementById("output");
  3.     let text = document.getElementById("input").value;
  4.     let sentences = text.split('.').filter(Boolean);
  5.     let counter = 0;
  6.     let currentParagraph = [];
  7.     while (sentences.length > 0) {
  8.       if (counter === 3) {
  9.         outputRef.innerHTML += `<p>${currentParagraph.join('.')}.</p>`;
  10.         counter = 0;
  11.         currentParagraph = [];
  12.       }
  13.  
  14.       let currentSentence = sentences.shift();
  15.       currentParagraph.push(currentSentence);
  16.       counter++;
  17.     }
  18.  
  19.     outputRef.innerHTML += `<p>${currentParagraph.join('.')}.</p>`;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement