Skip to content

Commit 7b0c483

Browse files
committed
feat: added capitalize algorithm
1 parent 9b32db2 commit 7b0c483

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

String/Capitalize.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @function capitalize
3+
* @description Will convert the first character of the string to uppercase
4+
* @param {String} str - The input string
5+
* @returns {String} Capitalized string
6+
* @example capitalize("hello") => Hello
7+
* @example capitalize("_ello") => _ello
8+
*/
9+
const capitalize = (str) => {
10+
if (typeof str !== 'string') {
11+
throw new Error('Argument should be string')
12+
}
13+
14+
return str[0].toLocaleUpperCase() + str.slice(1)
15+
}
16+
17+
export default capitalize

String/test/Capitalize.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import capitalize from '../Capitalize'
2+
3+
describe('Testing the Capitalize function', () => {
4+
it('returns capitalized strings', () => {
5+
expect(capitalize('hello')).toBe('Hello')
6+
expect(capitalize('HELLO world')).toBe('HELLO world')
7+
expect(capitalize('_ello')).toBe('_ello')
8+
})
9+
})

package-lock.json

Lines changed: 10 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)