I have a task to change string input into something new with array, cause my tutor said so. For example
Input : Soda Hello
Output : * od * * ell *
This is my code :
var r1 = require('readline-sync')
var str = r1.question('Input : ')
var output = '';
var array = str.split(' ')
for(var i=0;i<array.length;i++){
for(var l=0;l<array[i].length;l++){
if(l!=0 && l!=(array[i].length-1)){
output+= array[i][l]
}
else{
output += '*'
}
}
output += ' '
}
console.log(output)
Is there any way to change first character in the first word without turn it again as array? Because when I try this code
for(var i=0;i<array.length;i++){
for(var l=0;l<array[i].length;l++){
if(l!=0 && l!=(array[i].length-1)){
array[i][l]='*'
}
}
It doesn't create any change. Should I turn the words into array first or there's another way?