Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let password = input.shift();
- for (let line of input) {
- if (line === 'Done') {
- console.log(`Your password is: ${password}`)
- break;
- }
- let tokens = line.split(' ');
- let command = tokens[0];
- switch (command) {
- case 'TakeOdd':
- takeodd(password);
- break;
- case 'Cut':
- cut(tokens[1],tokens[2])
- break;
- case 'Substitute':
- substitute(tokens[1],tokens[2])
- break;
- }
- }
- function takeodd(string){
- let newPassword = "";
- for ( let i= 0; i < string.length; i++){
- if(i%2 != 0){
- newPassword += string[i]
- }
- }
- password = newPassword;
- console.log(newPassword)
- }
- function cut(startIndex,endIndex) {
- startIndex = Number(startIndex);
- endIndex = Number(endIndex);
- let cutMessage = password.substring(startIndex, startIndex + endIndex);
- password = password.replace(cutMessage, '');
- console.log(password);
- }
- function substitute(currentChar,newChar) {
- if(password.includes(currentChar)) {
- while(password.search(currentChar) !== -1) {
- password = password.replace(currentChar,newChar);
- }
- console.log(password)
- } else {
- console.log("Nothing to replace!")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement