Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function problemTwo(input) {
- let pattern = /!(?<command>[A-Z][a-z]{2,})!\:\[(?<message>[A-Za-z]{7,})\]/g
- let commands = input.shift();
- commands = Number(commands);
- let result = '';
- for (let line of input) {
- let match = line.match(pattern);
- if (match !== null) {
- match = pattern.exec(line);
- let message = match.groups.message;
- result += `${match.groups.command}: `;
- for (let i = 0; i < message.length; i++) {
- let value = message.charCodeAt(i);
- result += value + ' ';
- }
- console.log(result);
- } else {
- console.log(`The message is invalid`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement