function titleCase(str) {
var convertToArray = str.toLowerCase().split(" ");
var result = convertToArray.map(function(val) {
return val.replace(val.charAt(0), val.charAt(0).toUpperCase());
});
return result.join(" ");
}
titleCase("I'm a little tea pot");
I was going for a similar approach to Solution 2, but I finally gave in. I was getting close but when I saw the solution, I was never going to get it right. Anyways, what I specifically donât understand is where does âvalâ come from? is that a paremeter built-in to JS? I just see it doesnât get defined at all yet the code runs. If it is a built-in parameter (like say, âpropâ and âidâ which also sent me spinning), where can I find a list of these built-in parameters? Itâs driving me nuts seeing these (what appear to me) random undefined variables all over the code.
Any info appreciated. Thank you.
Copying the solutions will make it harder and harder to keep up with the challenges and understand whatâs going on. I recommend instead asking questions on the forum to help you get un-stuck.
Anyways, what do you know about the map() method? val is the argument to the callback function for the map() method. It is not any sort of special variable name.
Similarly, prop and id are not random or undefined or special âbuilt inâ parameters either. They are just some names of some variables.
I understand. val is a callback function. I mistook it for a variable.
Sometimes Iâd rather ask stupid questions than waste time overthinking things.
Thank you.
val is not a callback function. It is a variable inside of a callback function. I think you may have some misunderstandings on how function arguments work.