Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let toSearchForDigits = input[0].slice().split('');
- let coolTreshold = [];
- // изчисляване на Threshold;
- for (let i = 0; i < toSearchForDigits.length; i++) {
- if (toSearchForDigits[i].charCodeAt(0) >= 48 && toSearchForDigits[i].charCodeAt(0) <= 57) {
- let number = Number(toSearchForDigits[i]);
- coolTreshold.push(number);
- };
- }
- let sum = BigInt;
- if (coolTreshold.length > 0) {
- sum = 1;
- for (let num of coolTreshold) {
- sum *= num;
- }
- } else {
- sum = 0;
- }
- //RegEx проверка
- let pattern = /(::|\*\*)([A-Z][a-z]{2,})\1/;
- let inputArray = input[0].split(', ').join(' ').split(' ');
- let totalMatches = 0;
- let coolMatches = [];
- for (let i = 0; i < inputArray.length; i++) {
- let line = inputArray[i];
- let match = pattern.exec(line);
- if (match !== null) {
- totalMatches++
- let sumOfSymbols = 0;
- let wordOnly = match[2];
- for (let symbol of wordOnly) {
- sumOfSymbols += Number(symbol.charCodeAt(0));
- }
- if (sumOfSymbols >= sum) {
- coolMatches.push(match[0]);
- }
- }
- }
- console.log(`Cool threshold: ${sum}`);
- console.log(`${totalMatches} emojis found in the text. The cool ones are:`);
- for (let match of coolMatches) {
- console.log(match);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement