Skip to content

Commit e40c62d

Browse files
chore: merge Tests for check flat case (TheAlgorithms#689)
* update function documentation and name to match js convention * add additional documentation explaining what the function does * add tests for checkFlatCase function * fix standard.js errors
1 parent 401ccd0 commit e40c62d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

String/CheckFlatCase.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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 }

String/test/CheckFlatCase.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy