Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (input = []) {
- let text = input[0];
- let patternNumbers = /([0-9])/g;
- let patternEmojis = /([:*]{2})([A-Z][a-z]{2,})\1/g
- let nums = text.match(patternNumbers);
- let emojis = text.match(patternEmojis);
- let coolThreshold = 1;
- for (let num of nums) {
- num = Number(num);
- coolThreshold *= num;
- }
- let coolEmojis = [];
- for (let line of emojis) {
- //let currLine = line;
- let regexL = /[A-Z][a-z]{2,}/;
- let coolEmoji = line.match(regexL);
- //console.log(coolEmoji);
- let currEmoji = coolEmoji[0].split('');
- let currAscii = 0;
- currEmoji.forEach(letter => {
- letter = letter.charCodeAt(0);
- currAscii += letter;
- });
- if (currAscii >= coolThreshold) {
- coolEmojis.push(line);
- }
- }
- console.log(`Cool threshold: ${coolThreshold}`);
- console.log(`${emojis.length} emojis found in the text. The cool ones are:`);
- if (coolEmojis.length > 0) {
- console.log(`${coolEmojis.join('\n')}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement