Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function modernTimesOfHashTag(text) {
- let sentence = text.split(' ');
- let special = [];
- for (let part of sentence) {
- if (part.startsWith('#') && part.length > 1) {
- let specialWord = part.substring(1);
- let isLettersOnly = true;
- for (let i = 0; i < specialWord.length; i++) {
- let charCode = specialWord.charCodeAt(i);
- if ((charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) {
- isLettersOnly = false;
- break;
- }
- }
- if (isLettersOnly) {
- special.push(specialWord);
- }
- }
- }
- console.log(special.join('\n'));
- }
- OR
- function modernTimesOfHashTag(text) {
- let sentence = text.split(' ');
- let special = [];
- for (let part of sentence) {
- if (part.startsWith('#') && part.length > 1) {
- let specialWord = part.substring(1);
- let isLettersOnly = true;
- for (let char of specialWord) {
- if (!/[a-zA-Z]/.test(char)) {
- isLettersOnly = false;
- break;
- }
- }
- if (isLettersOnly) {
- special.push(specialWord);
- }
- }
- }
- console.log(special.join('\n'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement