Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let str = input.shift()
- for(let element of input){
- if(element === 'End'){
- break
- }
- if(element.includes('Translate')){
- let [command, char, replacement] = element.split(' ')
- if(str.includes(char)){
- str = str.split(char)
- str = str.join(replacement)
- console.log(str)
- }
- }
- else if(element.includes('Includes')){
- let [command, subStr] = element.split(' ')
- if(str.includes(subStr)){
- console.log('True');
- }
- else{
- console.log('False');
- }
- }
- else if(element.includes('Start')){
- let [command, subStr] = element.split(' ')
- if(str.indexOf(subStr) === 0){
- console.log('True');
- }
- else{
- console.log('False');
- }
- }
- else if(element.includes('FindIndex')){
- let [command, char] = element.split(' ')
- let lastIndex = str.lastIndexOf(char)
- if(lastIndex !== -1){
- console.log(lastIndex);
- }
- }
- else if(element.includes('Remove')){
- let [command, startIndex, count] = element.split(' ')
- startIndex = +startIndex
- count = +count
- str = str.split('')
- str.splice(startIndex, count)
- str = str.join('')
- console.log(str);
- }
- else if(element === 'Lowercase'){
- str = str.toLowerCase()
- console.log(str);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement