File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 1- // CheckFlatCase method checks the given string is in flatcase or not.
1+ // checkFlatCase method checks if the given string is in flatcase or not. Flatcase is a convention
2+ // where all letters are in lowercase, and there are no spaces between words.
3+ // thisvariable is an example of flatcase. In camelCase it would be thisVariable, snake_case this_variable and so on.
24
35// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
46
57/**
6- * CheckFlatCase method returns true if the string in flatcase, 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 flatcase, else return false.
8+ * checkFlatCase method returns true if the string in flatcase, else return the false.
9+ * @param {string } varname the name of the variable to check.
10+ * @returns { boolean } return true if the string is in flatcase, else return false.
911 */
10- const CheckFlatCase = ( varname ) => {
12+ const checkFlatCase = ( varname ) => {
1113 // firstly, check that input is a string or not.
1214 if ( typeof varname !== 'string' ) {
1315 return new TypeError ( 'Argument is not a string.' )
@@ -17,4 +19,4 @@ const CheckFlatCase = (varname) => {
1719 return pat . test ( varname )
1820}
1921
20- module . exports = CheckFlatCase
22+ export { checkFlatCase }
Original file line number Diff line number Diff line change 1+ import { checkFlatCase } from '../CheckFlatCase'
2+
3+ describe ( 'checkFlatCase function' , ( ) => {
4+ it ( 'should return false when the input string is not in flatcase' , ( ) => {
5+ const actual = checkFlatCase ( 'this is not in flatcase' )
6+ expect ( actual ) . toBe ( false )
7+ } )
8+
9+ it ( 'should return true when the input string is a single letter character' , ( ) => {
10+ const actual = checkFlatCase ( 'a' )
11+ expect ( actual ) . toBe ( true )
12+ } )
13+
14+ it ( 'should return true when the input string is a string of lowercase letter characters with no spaces' , ( ) => {
15+ const actual = checkFlatCase ( 'abcdefghijklmnopqrstuvwxyz' )
16+ expect ( actual ) . toBe ( true )
17+ } )
18+ } )
You can’t perform that action at this time.
0 commit comments