X Tutup
Skip to content

Commit e48f5e2

Browse files
add CheckPascalCase method
1 parent 77c3a9e commit e48f5e2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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 'Not string(s)'
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