Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function stringGame(input) {
- let wordStr = input.shift();
- let comandLine = input.shift();
- while (comandLine !== 'Done') {
- if (comandLine.includes('Change')) {
- let [command, charts, replace] = comandLine.split(' ');
- if (wordStr.includes(charts)) {
- wordStr = wordStr.split(charts).join(replace);
- }
- console.log(wordStr)
- } else if (comandLine.includes('Includes')) {
- let [command, substring] = comandLine.split(' ');
- wordStr.includes(substring) ?console.log('True'): console.log('False');
- } else if (comandLine.includes('End')) {
- let [command, substring] = comandLine.split(' ');
- let lengthSubstr = substring.length;
- let stringLength = wordStr.length;
- if (wordStr.lastIndexOf(substring)) {
- let index = wordStr.lastIndexOf(substring);
- index + lengthSubstr === stringLength ? console.log(`True`):console.log(`False`);
- } else {
- console.log('False');
- }
- } else if (comandLine.includes('Uppercase')) {
- wordStr = wordStr.toUpperCase();
- console.log(wordStr)
- } else if (comandLine.includes('FindIndex')) {
- let [command, char] = comandLine.split(' ')
- let index = wordStr.indexOf(char)
- console.log(index)
- } else if (comandLine.includes('Cut')) {
- let [command, start, count] = comandLine.split(' ');
- start = Number(start);
- count = Number(count);
- wordStr = wordStr.slice(start, start + count);
- console.log(wordStr);
- }
- comandLine = input.shift()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement