I'm working on some map() practice and am stuck. I am attempting to capitalize the first letter in each word.
I believe I am following the correct syntax for charAt() but it is getting word.charAt() is not a function.
const titleCased = () => {
const cased = tutorials.map((string) => {
return string.split(' ')
})
let newCase = cased.forEach((word) => {
return word.charAt(0).toUpperCase() + word.slice(1)
})
return newCase
}
I'm not looking for an answer, I really wanna figure it out myself!
Hopefully someone can give me some tips though, when I run my debugger it completely skips past newCase as well.. I'm sure I a am misunderstanding my scope.
tutorials variable for ref.
const tutorials = [
'what does the this keyword mean?',
'What is the Constructor OO pattern?',
'implementing Blockchain Web API',
'The Test Driven Development Workflow',
'What is NaN and how Can we Check for it',
'What is the difference between stopPropagation and preventDefault?',
'Immutable State and Pure Functions',
'what is the difference between == and ===?',
'what is the difference between event capturing and bubbling?',
'what is JSONP?',
]
EDIT: Update
So this is where I've gotten, Phil(below) mentioned that my original forEach() funct now map() is doing nothing with the return value of the callback.
I am very new and doing my best, I'm struggling to understand how to relate the return value.
const titleCased = () => {
const cased = tutorials.map((string) => {
return string.split(' ')
})
let newCase = cased.map((word) => {
return word[0].charAt(0).toUpperCase() + word[0].slice(1)
})
return newCase
}
I finally did the thing
function titleCased() {
const cased = tutorials.map((cb) => {
const newCase = cb
.split(' ')
.map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1)
})
.join(' ')
return newCase
})
return cased
}