X Tutup
Skip to content

Commit 50cb217

Browse files
authored
chore: Merge pull request TheAlgorithms#659 from suryapratapsinghsuryavanshi/master
CheckCamelCase and CheckPascalCase method added to String category
2 parents 1f5dadd + 0ea955b commit 50cb217

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

String/CheckCamelCase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// CheckCamelCase method checks the given string is in camelCase or not.
2+
3+
// Problem Source & Explanation: https://en.wikipedia.org/wiki/Camel_case
4+
5+
/**
6+
* CheckCamelCase method returns true if the string in camelCase, else return the false.
7+
* @param {String} varName the name of the variable to check.
8+
* @returns `Boolean` return true if the string is in camelCase, else return false.
9+
*/
10+
const CheckCamelCase = (varName) => {
11+
// firstly, check that input is a string or not.
12+
if (typeof varName !== 'string') {
13+
return new TypeError('Argument is not a string.')
14+
}
15+
16+
const pat = /^[a-z][A-Za-z]*$/
17+
return pat.test(varName)
18+
}
19+
20+
module.exports = CheckCamelCase

String/CheckPascalCase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// CheckPascalCase method checks the given string is in PascalCase or not.
2+
3+
// Problem Source & Explanation: https://www.theserverside.com/definition/Pascal-case
4+
5+
/**
6+
* CheckPascalCase method returns true if the string in PascalCase, else return the false.
7+
* @param {String} VarName the name of the variable to check.
8+
* @returns `Boolean` return true if the string is in PascalCase, else return false.
9+
*/
10+
const CheckPascalCase = (VarName) => {
11+
// firstly, check that input is a string or not.
12+
if (typeof VarName !== 'string') {
13+
return new TypeError('Argument is not a string.')
14+
}
15+
16+
const pat = /^[A-Z][A-Za-z]*$/
17+
return pat.test(VarName)
18+
}
19+
20+
module.exports = CheckPascalCase

0 commit comments

Comments
 (0)
X Tutup