Given a string S, print it after changing the middle element to * (if the length of the string is even, change the 2 middle elements to *). Sample Testcase : INPUT hello OUTPUT he*lo
Given a string S, print it after changing the middle element to * (if
the length of the string is even, change the 2 middle elements to *).
Sample Testcase :
INPUT
hello
OUTPUT
he*lo
const readline = require('readline');
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var data = userInput[0].split(" ");
var a = String(data[0]);
var b = a.split('')
var c = b.length
var d = Math.round(c/2)
{ if(c%2!==0)
b[d-1]="*"
else
b[d]="*";
b[d-1]="*"
}
var e=b.join('')
console.log(e);
});
Sample Testcase :
INPUT
hello
OUTPUT
he*lo
const readline = require('readline');
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var data = userInput[0].split(" ");
var a = String(data[0]);
var b = a.split('')
var c = b.length
var d = Math.round(c/2)
{ if(c%2!==0)
b[d-1]="*"
else
b[d]="*";
b[d-1]="*"
}
var e=b.join('')
console.log(e);
});
Comments
Post a Comment