kstoyanov

02. Modern Times of #(HashTag) v2 ascii

Jul 17th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(inputString) {
  2.  
  3.     let words = inputString.split(' ');
  4.  
  5.     let wordsWithHashtag = words.filter((word) => word.startsWith('#') && word.length > 1);
  6.  
  7.     let validWord = wordsWithHashtag
  8.         .filter((word) => {
  9.             let characters = word.split('').slice(1);
  10.             return (characters.every((char) => isLower(char) || isUpper(char)));
  11.         })
  12.         .map((word) => word.substring(1));
  13.  
  14.     console.log(validWord.join('\n'))
  15.  
  16.  
  17.     function isLower(char) {
  18.         let asciiValue = char.charCodeAt(0);
  19.         return asciiValue >= 97 && asciiValue <= 122;
  20.     }
  21.  
  22.     function isUpper(char) {
  23.         let asciiValue = char.charCodeAt(0);
  24.         return asciiValue >= 65 && asciiValue <= 90;
  25.     }
  26. }
Add Comment
Please, Sign In to add comment