Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let text = input.shift().split(' ')
- for (let i = 0; i < text.length; i++) {
- if (text[i].endsWith(',')) {
- let a = text[i].replace(',','')
- text[i] = a;
- }
- if (text[i].endsWith('.')) {
- let a = text[i].replace('.','')
- text[i] = a;
- }
- }
- let result = findAllDigits();
- console.log(`Cool threshold: ${result}`)
- let count = 0;
- let arr = [];
- for (const el of text) {
- if (isSurrounded(el) && isLengthValid(el) && isStartsWithCapitalLetter(el) && isContinuesWithLowerCaseLetter(el)){
- count++;
- arr.push(el)
- }
- }
- console.log(`${count} emojis found in the text. The cool ones are:`)
- let emojies = arr.join(' ');
- emojies = emojies.replace('::','')
- while (emojies.indexOf('::') > -1) {
- emojies = emojies.replace('::','')
- }
- while (emojies.indexOf('**') > -1) {
- emojies = emojies.replace('**','')
- }
- let arrEmojies = emojies.split(' ')
- for (const el of arrEmojies) {
- let sum = 0;
- for (let i = 0; i < el.length; i++) {
- let asciiValue = el[i].charCodeAt();
- sum += asciiValue;
- }
- if (sum > result) {
- console.log(el)
- }
- }
- function isSurrounded(el) {
- let isTrue = false;
- if ((el.startsWith('::') && el.endsWith('::'))
- || (el.startsWith('**') && el.endsWith('**'))) {
- isTrue = true;
- } else {
- isTrue = false
- }
- return isTrue;
- }
- function isLengthValid(el) {
- let isTrue = false;
- if (el.startsWith('::')) {
- el = el.replace('::','');
- } if (el.endsWith('::')) {
- el = el.replace('::','');
- } if (el.startsWith('**')) {
- el = el.replace('**','');
- } if (el.endsWith('**')) {
- el = el.replace('**','');
- } if (el.length >= 3) {
- isTrue = true;
- }
- return isTrue;
- }
- function isStartsWithCapitalLetter(el) {
- let isTrue = false;
- if (el.startsWith('::')) {
- el = el.replace('::','');
- } if (el.endsWith('::')) {
- el = el.replace('::','');
- } if (el.startsWith('**')) {
- el = el.replace('**','');
- } if (el.endsWith('**')) {
- el = el.replace('**','');
- }
- let asciiValue = el.charCodeAt(0);
- return asciiValue >= 65 && asciiValue <= 90;
- }
- function isContinuesWithLowerCaseLetter(el) {
- let isTrue = false;
- if (el.startsWith('::')) {
- el = el.replace('::','');
- } if (el.endsWith('::')) {
- el = el.replace('::','');
- } if (el.startsWith('**')) {
- el = el.replace('**','');
- } if (el.endsWith('**')) {
- el = el.replace('**','');
- }
- for (let i = 1; i < el.length; i++) {
- let asciiValue = el[i].charCodeAt(0);
- if (el[i] == el[i].toLowerCase() && (asciiValue >= 97 && asciiValue <= 122)){
- isTrue = true;
- } else {
- isTrue = false;
- break;
- }
- }
- return isTrue;
- }
- function findAllDigits(el) {
- let arr = [];
- let multiplying = 1;
- for (const el of text) {
- for (let i = 0; i < el.length; i++) {
- let asciiValue = el[i].charCodeAt();
- if (asciiValue >= 48 && asciiValue <= 57) {
- arr.push(el[i])
- }
- }
- }
- for (const el of arr) {
- multiplying *= Number(el);
- }
- return multiplying;
- }
- }
- solve(
- [
- 'In the Sofia Zoo there are 311 animals in total! ::Smiley:: This includes 3 **Tigers**, 1 ::Elephant:, 12 **Monk3ys**, a **Gorilla::, 5 ::fox:es: and 21 different types of :Snak::Es::. ::Mooning:: **Shy**'
- ]
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement