Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function f(input) {
- let [firstPart, secondPart, thirdPart] = input[0].split('|');
- let arrThirdPart = thirdPart.split(' ');
- let firstPartReg = /\$([A-Z]+)\$|\#([A-Z]+)\#|\%([A-Z]+)\%|\*([A-Z]+)\*|\&([A-Z]+)\&/g;
- let secondPartReg = /([0-9][0-9]\:[0-9][0-9])/g;
- let length;
- let charCode;
- let firstLetters;
- let code = new Map();
- let filteredCode = new Map();
- let sentense = [];
- if (firstPart.match(firstPartReg)) {
- let firstLettersArr = firstPart.match(firstPartReg);
- firstLetters = firstLettersArr[0].replace(/[#$%*&]/g, '');
- }
- if (secondPart.match(secondPartReg)) {
- let result = secondPart.match(secondPartReg);
- for (let inputRow of result) {
- [charCode, length] = inputRow.split(':');
- let firstLetter = String.fromCharCode(charCode);
- code.set(firstLetter, length);
- }
- }
- for (let inputRow of firstLetters) {
- if (code.has(inputRow)) {
- let char = code.get(inputRow);
- filteredCode.set(inputRow, Number(char));
- }
- }
- for (let inputRow of filteredCode) {
- for (let inputArr of arrThirdPart) {
- if (inputArr.startsWith(inputRow[0]) && inputArr.length === inputRow[1] + 1) {
- sentense.push(inputArr);
- }
- }
- }
- console.log(sentense.join('\n'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement