Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let strForMan = input.shift();
- let command = input.shift();
- while(command !== 'Finish'){
- if(command.includes("Replace")){
- let arrReplace = command.split(' '); //Replace a e
- strForMan=strForMan.split(arrReplace[1]).join(arrReplace[2]);
- console.log(strForMan);
- }else if(command.includes("Cut")){ // {startIndex} {endIndex}
- let arrCut = command.split(' ');
- let strsplit = strForMan.split('');
- let startI = Number(arrCut[1]);
- let endI = Number(arrCut[2]);
- if(startI>=0 && endI<strsplit.length){
- strsplit.splice(startI, endI);
- strForMan = strsplit.join('');
- console.log(strForMan);
- }else{
- console.log('Invalid indexes!');
- }
- }else if(command.includes("Make")){ // {Upper/Lower}
- if(command.includes("Upper")){
- strForMan = strForMan.toUpperCase();
- console.log(strForMan);
- }else{
- strForMan = strForMan.toLowerCase();
- console.log(strForMan);
- }
- }else if(command.includes("Check")){ // {string}
- let checkArr = command.split(' ');
- if(strForMan.includes(checkArr[1])){
- console.log(`Message contains ${checkArr[1]}`);
- }else{
- console.log(`Message doesn't contain ${checkArr[1]}`);
- }
- }else if(command.includes("Sum")){ // {startIndex} {endIndex}
- let sumArr = command.split(' ');
- let startI = Number(sumArr[1]);
- let endI = Number(sumArr[2]);
- let c = 0;
- if(startI>=0 && endI<strForMan.length){
- let substr = strForMan.substr(startI, endI);
- //console.log(substr);
- for (let i = 0; i < substr.length; i++) { //substr е стринг = LIKE
- c += substr.charCodeAt(i);
- }
- console.log(c);
- c = 0;
- }else{
- console.log('Invalid indexes!');
- }
- }
- command = input.shift();
- }
- }
- solve([
- 'ILikeSharan',
- 'Replace a e',
- 'Make Upper',
- 'Check SHEREN',
- 'Sum 1 4',
- 'Cut 1 4',
- 'Finish'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement