Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function activationKeys(arr) {
- let string = arr.shift();
- for (let line of arr) {
- let instructions = line.split(">>>");
- if (instructions[0] === "Contains") {
- if (string.includes(instructions[1])) {
- console.log(`${string} contains ${instructions[1]}`);
- } else {
- console.log("Substring not found!");
- }
- } else if (instructions[0] === "Flip") {
- let startIndex = Number(instructions[2]);
- let endIndex = Number(instructions[3]);
- let substring = string.substring(startIndex, endIndex);
- if (instructions[1] === "Upper") {
- substring = substring.toUpperCase();
- } else {
- substring = substring.toLowerCase();
- }
- string = string.slice(0, startIndex) + substring + string.slice(endIndex);
- console.log(string);
- } else if (instructions[0] === "Slice") {
- let startIndex = Number(instructions[1]);
- let endIndex = Number(instructions[2]);
- string = string.slice(0, startIndex) + string.slice(endIndex);
- console.log(string);
- } else if (instructions[0] === "Generate") {
- console.log(`Your activation key is: ${string}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement