Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let n = Number(input[0]);
- for(let i = 1; i <= n; i++) {
- let line = input[i];
- let regex = /!([A-Z][a-z]{3,})!:\[([A-Za-z]{3,})\]/g;
- let isValid = regex.test(line);
- if(isValid) {
- let match = regex.exec(line);
- let command = match[1];
- let message = match[2];
- console.log(`Command: ${command} Message: ${message}`);
- } else {
- console.log('The message is invalid');
- }
- }
- }
- solve([
- '3',
- '!play!:[TheNewSong]',
- '!Ride!:[Bike]',
- '!Watch!:[LordofTheRings]'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement