Advertisement
bebo231312312321

Untitled

Apr 2nd, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function stringGame(input) {
  2.     let wordStr = input.shift();
  3.     let comandLine = input.shift();
  4.     while (comandLine !== 'Done') {
  5.         if (comandLine.includes('Change')) {
  6.             let [command, charts, replace] = comandLine.split(' ');
  7.             if (wordStr.includes(charts)) {
  8.                 wordStr = wordStr.split(charts).join(replace);
  9.             }
  10.             console.log(wordStr)
  11.         } else if (comandLine.includes('Includes')) {
  12.             let [command, substring] = comandLine.split(' ');
  13.             wordStr.includes(substring) ?console.log('True'): console.log('False');
  14.            
  15.         } else if (comandLine.includes('End')) {
  16.             let [command, substring] = comandLine.split(' ');
  17.             let lengthSubstr = substring.length;
  18.             let stringLength = wordStr.length;
  19.             if (wordStr.lastIndexOf(substring)) {
  20.                 let index = wordStr.lastIndexOf(substring);
  21.                 index + lengthSubstr === stringLength ? console.log(`True`):console.log(`False`);
  22.                
  23.             } else {
  24.                 console.log('False');
  25.             }
  26.         } else if (comandLine.includes('Uppercase')) {
  27.             wordStr = wordStr.toUpperCase();
  28.             console.log(wordStr)
  29.         } else if (comandLine.includes('FindIndex')) {
  30.             let [command, char] = comandLine.split(' ')
  31.             let index = wordStr.indexOf(char)
  32.             console.log(index)
  33.         } else if (comandLine.includes('Cut')) {
  34.             let [command, start, count] = comandLine.split(' ');
  35.             start = Number(start);
  36.             count = Number(count);
  37.             wordStr = wordStr.slice(start, start + count);
  38.             console.log(wordStr);
  39.         }
  40.         comandLine = input.shift()
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement