Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function activationKey(arr = []) {
- let key = arr[0];
- for (let i = 1; i < arr.length; i++) {
- const tokens = arr[i].split('>>>');
- const command = tokens[0];
- if (command === 'Generate') {
- break;
- } else if (command === 'Contains') {
- const substring = tokens[1];
- if (key.includes(substring)) {
- console.log(`${key} contains ${substring}`);
- } else {
- console.log('Substring not found!');
- }
- } else if (command === 'Flip'){
- const typeOfCommand = tokens[1];
- const startIndex = Number(tokens[2]);
- const endIndex = Number(tokens[3]);
- let changedKey = key.substring(startIndex, endIndex);
- if (typeOfCommand === 'Lower') {
- changedKey = changedKey.toLowerCase();
- key = key.substring(0, startIndex) + changedKey + key.substring(endIndex);
- } else if (typeOfCommand === 'Upper') {
- changedKey = changedKey.toUpperCase();
- key = key.substring(0, startIndex) + changedKey + key.substring(endIndex);
- }
- console.log(key);
- } else if (command === 'Slice') {
- const startIndex = Number(tokens[1]);
- const endIndex = Number(tokens[2]);
- key = key.substring(0, startIndex) + key.substring(endIndex);
- console.log(key);
- }
- }
- console.log(`Your activation key is: ${key}`);
- }
Add Comment
Please, Sign In to add comment