Advertisement
TZinovieva

Modern Times of #(HashTag) JS Fundamentals

Mar 7th, 2023 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function modernTimesOfHashTag(text) {
  2.   let sentence = text.split(' ');
  3.   let special = [];
  4.  
  5.   for (let part of sentence) {
  6.     if (part.startsWith('#') && part.length > 1) {
  7.       let specialWord = part.substring(1);
  8.       let isLettersOnly = true;
  9.       for (let i = 0; i < specialWord.length; i++) {
  10.         let charCode = specialWord.charCodeAt(i);
  11.         if ((charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) {
  12.           isLettersOnly = false;
  13.           break;
  14.         }
  15.       }
  16.       if (isLettersOnly) {
  17.         special.push(specialWord);
  18.       }
  19.     }
  20.   }
  21.  
  22.   console.log(special.join('\n'));
  23. }
  24.  
  25.  
  26. OR
  27.  
  28. function modernTimesOfHashTag(text) {
  29.   let sentence = text.split(' ');
  30.   let special = [];
  31.  
  32.   for (let part of sentence) {
  33.     if (part.startsWith('#') && part.length > 1) {
  34.       let specialWord = part.substring(1);
  35.       let isLettersOnly = true;
  36.       for (let char of specialWord) {
  37.         if (!/[a-zA-Z]/.test(char)) {
  38.           isLettersOnly = false;
  39.           break;
  40.         }
  41.       }
  42.       if (isLettersOnly) {
  43.         special.push(specialWord);
  44.       }
  45.     }
  46.   }
  47.  
  48.   console.log(special.join('\n'));
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement