Guest User

Untitled

a guest
Jun 28th, 2020
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function solve(input) {
  2. let pass = input.shift();
  3.  
  4. for(const line of input) {
  5. const tokens = line.split(' ');
  6. const cmd = String(tokens[0]);
  7.  
  8. if(cmd === 'TakeOdd') {
  9. let raw = ''
  10. for(let i = 0; i < pass.length; i++) {
  11. if(i % 2 !== 0) {
  12. raw += pass[i];
  13. }
  14. }
  15. pass = raw;
  16. console.log(pass);
  17.  
  18. } else if (cmd === 'Cut') {
  19. const index = tokens[1];
  20. const length = tokens[2];
  21. const substr = pass.substr(index, length);
  22. pass = pass.replace(substr, '');
  23. console.log(pass);
  24.  
  25. } else if (cmd === 'Substitute') {
  26. const substr = tokens[1];
  27. const substitute = tokens[2];
  28.  
  29. if(!pass.includes(substr)) {
  30. console.log("Nothing to replace!");
  31. } else {
  32. pass = pass.split(substr).join(substitute);
  33. console.log(pass);
  34. }
  35.  
  36. }
  37.  
  38. }
  39. console.log(`Your password is: ${pass}`);
  40. }
Add Comment
Please, Sign In to add comment