Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let string = input.shift();
- let [first, second, third] = string.split("|");
- let firstPattern = /([$\*#%&])([A-Z]+)\1/gm;
- let secondPattern = /([0-9]{2}\:[0-9]{2})+/gm;
- let firstGroup = Array.from(first.matchAll(firstPattern))[0][2];
- let secondGroup = Array.from(second.match(secondPattern));
- let ascis = [];
- let lengths = [];
- secondGroup.forEach(pair => {
- let [asciCode, length] = pair.split(":");
- ascis.push(Number(asciCode));
- lengths.push(Number(length));
- });
- let thirdGroup = third.split(" ");
- for (const letter of firstGroup) {
- thirdGroup.forEach(word => {
- let index = ascis.indexOf(letter.charCodeAt());
- if (word[0] === letter && word.length === lengths[index] + 1) {
- console.log(word);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment