Answer to Question #221571 in HTML/JavaScript Web Application for chandi

Question #221571

Given two strings inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.


"use strict";

process.stdin.resume();

process.stdin.setEncoding("utf-8");


let inputString = "";

let currentLine = 0;


process.stdin.on("data", (inputStdin) => {

 inputString += inputStdin;

});


process.stdin.on("end", (_) => {

 inputString = inputString.trim().split("\n").map((str) => str.trim());

 main();

});


function readLine() {

 return inputString[currentLine++];

}


/* Please do not modify anything above this line */


function main() {

 let inputString = readLine();

 const subString = readLine();

  

 /* Write your code here */

  

  }

}



1
Expert's answer
2021-07-31T07:43:07-0400
'use strict';


process.stdin.resume();
process.stdin.setEncoding('utf-8');


let inputString = '';
let currentLine = 0;


process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});


process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});


function readLine() {
    return inputString[currentLine++];
}


function main() {
    const inputString = readLine();
    const subString = readLine();


    let index = aqString.find(inputString, subString);
    if (isNaN(index) && index <= inputString.length) {
        console.log(inputString.split(index));
    }
}

Example:
Input 1:
JavaScript
S

Output 1:
Script

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS