Advertisement
ErolKZ

Untitled

Jan 26th, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. function solve() {
  2.  
  3. function findSentenceCount() {
  4.  
  5. let textInp = document.getElementById('input');
  6.  
  7. let sentences = textInp.value.split('. ');
  8.  
  9. // let sentences = 'JavaScript, often abbreviated as JS, is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm. Alongside HTML and CSS, JavaScript is one of the three core technologies of the World Wide Web. JavaScript enables interactive web pages and thus is an essential part of web applications. The vast majority of websites use it, and all major web browsers have a dedicated JavaScript engine to execute it. As a multi-paradigm language, JavaScript supports event-driven, functional, and imperative (including object-oriented and prototype-based) programming styles. It has an API for working with text, arrays, dates, regular expressions, and basic manipulation of the DOM, but the language itself does not include any I/O, such as networking, storage, or graphics facilities, relying for these upon the host environment in which it is embedded.';
  10.  
  11. // sentences = sentences.split('. ');
  12.  
  13. sentences = sentences.filter(el => el !== ' ' && el !== '');
  14.  
  15. console.log(sentences);
  16.  
  17. return [sentences.length, sentences];
  18.  
  19. }
  20.  
  21.  
  22. function paragraphCreation() {
  23.  
  24. let countOfSent = findSentenceCount()[0];
  25.  
  26. let sentences = findSentenceCount()[1];
  27.  
  28. let paragraphs = [];
  29.  
  30. let curPar = [];
  31.  
  32. if (countOfSent <= 3) {
  33.  
  34. let curSent = `<p>`;
  35.  
  36. while (sentences.length > 0) {
  37.  
  38. if (sentences.length === 1) {
  39.  
  40. curSent += `${sentences.shift()}`;
  41.  
  42. } else {
  43.  
  44. curSent += `${sentences.shift()}.`;
  45.  
  46. }
  47.  
  48. }
  49.  
  50. curSent += `</p>`;
  51.  
  52. curPar.push(curSent);
  53.  
  54. paragraphs.push(curPar);
  55.  
  56. curPar = [];
  57.  
  58. } else {
  59.  
  60. while (sentences.length > 0) {
  61.  
  62. let i = 1;
  63.  
  64. let curSent = `<p>`;
  65.  
  66. while (i <= 3) {
  67.  
  68. if (sentences.length === 1) {
  69.  
  70. curSent += `${sentences.shift()}`;
  71.  
  72. } else {
  73.  
  74. curSent += `${sentences.shift()}.`;
  75.  
  76. }
  77.  
  78. if (sentences.length === 0) {
  79.  
  80. break;
  81.  
  82. }
  83.  
  84. i++;
  85.  
  86. }
  87.  
  88. curSent += `</p>`;
  89.  
  90. curPar.push(curSent);
  91.  
  92. paragraphs.push(curPar);
  93.  
  94. curPar = [];
  95.  
  96. }
  97.  
  98.  
  99. }
  100.  
  101. console.log(paragraphs);
  102.  
  103.  
  104. let output = document.getElementById('output');
  105.  
  106. output.innerHTML = paragraphs.join(' ');
  107.  
  108.  
  109.  
  110. }
  111.  
  112.  
  113. paragraphCreation();
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement