Currently, I am delving into the world of TypeScript and facing a challenge. The task at hand involves creating a function that returns a string without its first and last character. Can anyone offer assistance with this problem? Below is the code along with my rationale behind it. I am hoping for some clarification. Thank you in advance.
To start off, I aimed to declare an empty string so that any character-filled string could be passed through. My goal was to then return this modified string with the help of the slice method, which removes characters based on their indices. Subsequently, I stored the altered string in a new variable called const answer
for easy retrieval using console.log.
export function removeChar(str: string): string {
var str = ""
return str.slice(1,-1)
}
const answer = removeChar("Hello, how are you?")
console.log(answer)