OK, first of all, let’s organize your code a little with “proper” indenting so it’s easier to read:
let newStr=0;
let newStr1=0
let newStr2=0
function titleCase(str) {
newStr=str.split("")
newStr1=newStr.map(v=>v.toLowerCase())
newStr2=newStr1.map(b=>b.replace(b.charAt(0)))
return newStr2
}
Ok, right off the bat I see a few problems. First of all, I wouldn’t use variable outside the scope of the function (the first three lines) because that can screw up the tests. Actually in this case it might not, but it’s a questionable coding practice and should be avoided. And there’s no need for them to be - they can be const
inside the function. (And someone might point out that you don’t need that many variables for this, but let’s not worry about that for now.)
The next thing I would want to do is find out what these things are doing. I would want to log out what those methods are doing:
let newStr=0;
let newStr1=0
let newStr2=0
function titleCase(str) {
newStr=str.split("")
console.log('newStr', newStr);
newStr1=newStr.map(v=>v.toLowerCase())
console.log('newStr1', newStr1);
newStr2=newStr1.map(b=>b.replace(b.charAt(0)))
console.log('newStr2', newStr2);
return newStr2
}
Doing that, I find that str is an array of all the characters.
"newStr is" ["I", "'", "m", " ", "a", " ", "l", "i", "t", "t", "l", "e", " ", "t", "e", "a", " ", "p", "o", "t"]
Is that what you want? Or do you want it broken up some other way? How do you get split to break it up on something other than every character.
The first map is doing what you expect.
The second map is not. replace takes two parameters. And depending on how you handle the split problem, this might not be how you want to do this.
Lastly, you are returning an array, but you’re supposed to be returning a sting. How do you get those individual strings in the array to join together into one string?
There is more than one way to solve this problem, let’s see what you can come up with.