String Slicing: 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.
Input
The first line of input contains a string inputString
The second line of input contains a string subString
Output
The output should be a sliced string or inputString (if the inputString does not include the subString)
function main() {
let inputString = readLine();
const subString = readLine();
/* Write your code here */
}
i want code in between write code here
'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));
}
}
Comments
Leave a comment