SHOW:
|
|
- or go back to the newest paste.
| 1 | function activationKey(arr = []) {
| |
| 2 | let key = arr[0]; | |
| 3 | ||
| 4 | for (let i = 1; i < arr.length; i++) {
| |
| 5 | const tokens = arr[i].split('>>>');
| |
| 6 | const command = tokens[0]; | |
| 7 | ||
| 8 | if (command === 'Generate') {
| |
| 9 | break; | |
| 10 | ||
| 11 | } else if (command === 'Contains') {
| |
| 12 | const substring = tokens[1]; | |
| 13 | ||
| 14 | if (key.includes(substring)) {
| |
| 15 | console.log(`${key} contains ${substring}`);
| |
| 16 | } else {
| |
| 17 | console.log('Substring not found!');
| |
| 18 | } | |
| 19 | } else if (command === 'Flip'){
| |
| 20 | const typeOfCommand = tokens[1]; | |
| 21 | const startIndex = Number(tokens[2]); | |
| 22 | const endIndex = Number(tokens[3]); | |
| 23 | let changedKey = key.substring(startIndex, endIndex); | |
| 24 | ||
| 25 | if (typeOfCommand === 'Lower') {
| |
| 26 | changedKey = changedKey.toLowerCase(); | |
| 27 | key = key.substring(0, startIndex) + changedKey + key.substring(endIndex); | |
| 28 | } else if (typeOfCommand === 'Upper') {
| |
| 29 | changedKey = changedKey.toUpperCase(); | |
| 30 | key = key.substring(0, startIndex) + changedKey + key.substring(endIndex); | |
| 31 | } | |
| 32 | console.log(key); | |
| 33 | } else if (command === 'Slice') {
| |
| 34 | const startIndex = Number(tokens[1]); | |
| 35 | const endIndex = Number(tokens[2]); | |
| 36 | ||
| 37 | key = key.substring(0, startIndex) + key.substring(endIndex); | |
| 38 | ||
| 39 | console.log(key); | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | console.log(`Your activation key is: ${key}`);
| |
| 44 | } |