Advertisement
simeonshopov

Format the text

May 17th, 2021
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.   let text = document.getElementById('input').value.split('.').filter(x => x.length >= 1);
  3.   const output = document.getElementById('output');
  4.   const numberPar = Math.ceil(text.length / 3);
  5.   for (let i = 0; i < numberPar; i++) {
  6.     const paragraph = extract3();
  7.     output.innerHTML += `<p>${paragraph}</p>`;
  8.   }
  9.  
  10.   function extract3 () {
  11.     let count = 0;
  12.     let result = [];
  13.     while (text.length > 0) {
  14.       if (count == 3) break;
  15.       const sentence = text.shift() + '.';
  16.       result.push(sentence);
  17.       count++;
  18.     }
  19.     return result.join('');
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement