Question:
Write a Javascript program to concatenate two strings except their first character.
Answer:
function concatStr (str01, str02) {
return str01.slice(1) + str02.slice(1);
}
> we declare a function 'concatStr'
> it has two parameters 'str01' & 'str02'
> we simply return the concatenated value of the slice method used on 'str01' & 'str02'
> we need to remove the first character from both the string inputs 'str01' & 'str02'
> so we want the slice to begin from the second character onwards
> thus we use 1 as the start parameter as the first character has the position of 0
No comments:
Post a Comment