Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const text = args.shift();
- const emojisArr = [];
- const coolThresholdNumbers = [];
- const patText = /[*]{2}(?<emoji>[A-Z][a-z]{2,})([*]){2}|([:]){2}(?<emoji2>[A-Z][a-z]{2,})[:]{2}/g;
- const patCoolThreshold = /\d/g;
- const takeEmoji = [...text.matchAll(patText)];
- const takeCoolNumbers = [...text.matchAll(patCoolThreshold)];
- takeEmoji.forEach((str) => {
- const [textSt] = str;
- emojisArr.push(textSt);
- });
- takeCoolNumbers.forEach((el) => {
- const [num] = el;
- coolThresholdNumbers.push(Number(num));
- });
- const coolThresholdSum = coolThresholdNumbers.join('')
- .split('')
- .map(Number)
- .reduce((acc, curnV) => acc * curnV);
- console.log(`Cool threshold: ${coolThresholdSum}`);
- console.log(`${emojisArr.length} emojis found in the text. The cool ones are:`);
- emojisArr.forEach((str) => {
- const takeStr = str.match(/[A-z]+/);
- let theCoolness = 0;
- takeStr[0].split('').forEach((ch) => {
- const takeLeftLetterIndex = text.indexOf(ch);
- const takeLetterCode = text.charCodeAt(takeLeftLetterIndex);
- theCoolness += takeLetterCode;
- });
- if (theCoolness > coolThresholdSum) {
- console.log(str);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement