Advertisement
kstoyanov

02. Format the Text

Sep 27th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function formattheText() {
  2.   const textAll = document.getElementById('input').textContent;
  3.   let titleArr = textAll.split('. ');
  4.   titleArr[titleArr.length - 1] = titleArr[titleArr.length - 1].slice(0, -1);
  5.   titleArr = titleArr.map((x) => `${x}.`);
  6.  
  7.   for (let i = 0; i < Math.ceil(titleArr.length / 3) ; i++) {
  8.     const p = document.createElement('p');
  9.     p.textContent = titleArr.slice(i * 3, i * 3 + 3).join(' ');
  10.     if (p.textContent.length > 0) {
  11.       document.getElementById('output').appendChild(p);
  12.     }
  13.   }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement