Advertisement
igelov

06. Format the Text

Apr 22nd, 2020
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let newText = document.getElementById('input').innerText;
  3.     let sentances = [];
  4.     sentances = newText.match(/[^\.!\?]+[\.!\?]+/g);
  5.     let par = [];
  6.     let cycle = sentances.length;
  7.     for (let i = 0; i < cycle; i++) {     // Gets every three sentences
  8.         par[i] = sentances.splice(0, 3).join('');
  9.     }
  10.     par = par.filter(item => item);//Removes the empty spaces
  11.  
  12.     //Bellow selects the output div and appends each element of the array in a new <p>
  13.     let paragraph = document.getElementById('output');
  14.     for (let i = 0; i < par.length; i++) {
  15.         let parHTML = document.createElement('p');
  16.         parHTML.textContent = par[i];
  17.         paragraph.appendChild(parHTML);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement