Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function stringManipulator(data) {
- let msg = data.shift();
- let commands = data.shift();
- while (commands !== 'End') {
- let command = commands.split(" ")
- switch (command[0]) {
- case 'Translate':
- let forReplace = command[1];
- let replaced = command[2];
- while (msg.includes(forReplace)) {
- msg = msg.replace(forReplace, replaced)
- }
- console.log(msg);
- break;
- case 'Includes':
- let word = command[1];
- if (msg.includes(word)) {
- console.log('True');
- } else {
- console.log('False');
- }
- break;
- case 'Start':
- let start = command[1];
- if (msg.startsWith(start)) {
- console.log('True');
- } else {
- console.log('False');
- }
- break;
- case 'Lowercase':
- msg = msg.toLowerCase()
- console.log(msg);
- break;
- case 'FindIndex':
- let find = command[1];
- let last = msg.lastIndexOf(find);
- console.log(last);
- break;
- case 'Remove':
- let begin = +(command[1]);
- let end = +(command[2]);
- msg = msg.substring(0, begin) + msg.substring(begin + end)
- console.log(msg);
- break;
- }
- commands = data.shift()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement