Advertisement
Neri0817

Untitled

Mar 11th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let result = [];
  3.   let words = input.split(" ");
  4.   for (let word of words) {
  5.     if (word.length > 1 && word.startsWith("#")) {
  6.       result.push(word.substring(1));
  7.     }
  8.   }
  9.   let final = [];
  10.   for (let word of result) {
  11.     let ch = word.split("");
  12.     let chL = ch.length;
  13.     let flag = true;
  14.  
  15.     for (let i = 0; i < chL; i++) {
  16.       let currWord = ch[i].charCodeAt(0);
  17.       if (
  18.         (currWord < 97 || currWord > 122) &&
  19.         (currWord < 65 || currWord > 90)
  20.       ) {
  21.         flag = false;
  22.       }
  23.     }
  24.  
  25.     if (flag) {
  26.       final.push(word);
  27.     }
  28.   }
  29.   final.forEach((word) => console.log(word));
  30. }
  31. solve("Nowadays everyone uses # to tag a #special word in #socialMedia");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement