-
js lowercase to uppercase |
Beta Was this translation helpful? Give feedback.
Answered by
hixb
Jul 19, 2022
Replies: 1 comment
-
` console.log(capitalize('hello world')) // Hello World |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hixb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`
const capitalize = (string) => {
const capitalizeRegex = /(?:^|\s+)\w/g
return string.toLowerCase().replace(capitalizeRegex, (match) => match.toUpperCase())
}
console.log(capitalize('hello world')) // Hello World
console.log(capitalize('hello WORLD')) // Hello World
`