Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let emojiPattern = /(::|\*\*)([A-Z][a-z]{2,})\1/g;
- let numPattern = /\d/g;
- let matchedEmoji = [...input[0].matchAll(emojiPattern)];
- let matchedNums = [...input[0].matchAll(numPattern)];
- let emojiArr = [];
- let numArr = [];
- let symArr = [];
- for (let i = 0; i < matchedEmoji.length; i++) {
- emojiArr.push(matchedEmoji[i][2]);
- symArr.push(matchedEmoji[i][1])
- }
- for (let i = 0; i < matchedNums.length; i++) {
- numArr.push(matchedNums[i][0])
- }
- let cool = 1;
- for (const line of numArr) {
- cool *= Number(line);
- }
- console.log(`Cool threshold: ${cool}`);
- console.log(`${emojiArr.length} emojis found in the text. The cool ones are:`);
- for (let i = 0; i < emojiArr.length; i++) {
- let asciiLine = emojiArr[i].split('').map(x => x.charCodeAt(0));
- let value = 0;
- for (const num of asciiLine) {
- value += num;
- }
- if (value > cool) {
- console.log(`${symArr[i]}${emojiArr[i]}${symArr[i]}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement