Advertisement
Kamend1

06. Format the text

Mar 20th, 2025
216
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;
  3.     let sentences = text.split('.').filter(s => s.trim() !== '');
  4.     let result = [];
  5.  
  6.     for (let i = 0; i < sentences.length; i += 3) {
  7.         let paragraphSentences = sentences.slice(i, i + 3).map(s => s.trim() + '.').join(' ');
  8.         let paragraph = `<p>${paragraphSentences}</p>`;
  9.         result.push(paragraph);
  10.     }
  11.  
  12.     document.getElementById('output').innerHTML = result.join('\n');
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement