Problem Description
There is a sequence of words in CamelCase as a string of letters, , having the following properties:
- It is a concatenation of one or more words consisting of English letters.
- All letters in the first word are lowercase.
- For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase. Given , determine the number of words in .
Example
s = "ontTwoThree"
There are words in the string: 'one', 'Two', 'Three'.
Function Description
Complete the camelcase function in the editor below.
camelcase has the following parameter(s):
- string s: the string to analyze
Returns
- int: the number of words in s
Input Format
A single line containing string s .
Sample Input
saveChangesInTheEditor
Sample Output
5
Explanation
String contains five words:
- save
- Change
- In
- The
- Editor
My Solution
function camelcase(s) {
// Write your code here
const strArr = s.split(/(?=[A-Z])/)
return strArr.length ;
}
Code Explanation
Firstly, I have split the given string not only that I have split string using REGEX /(?=[A-Z])/
. After splitting the length of array is returned.
Hope this post is helpful. I share my knowledge and teach people about programming and we have more than 12k @codewithyahi Instagram family.
Since you enjoyed reading my blog, why not buy me a coffee and support my work here!! https://www.buymeacoffee.com/yajindraβ
Top comments (0)