Skip to content

Commit e27bc0a

Browse files
committed
resolved conflicts
2 parents 1589263 + 17ac987 commit e27bc0a

File tree

6 files changed

+73
-17
lines changed

6 files changed

+73
-17
lines changed

Conversions/TitleCaseConversion.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
/*
2-
Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl
2+
Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl.
3+
[Title case](https://en.wikipedia.org/wiki/Title_case) is a style where all words are capitalized. Officially, title case
4+
does not capitalize some words, such as very short words like "a" or "is", but for the purposes of this function, a general approach
5+
is taken where all words are capitalized regardless of length.
36
*/
47

58
/**
6-
* The TitleCaseConversion converts a string into a title case string.
7-
* @param {String} inputString input string
8-
* @returns {String}
9+
* The titleCaseConversion function converts a string into a title case string.
10+
* @param {string} inputString The input string which can have any types of letter casing.
11+
* @returns {string} A string that is in title case.
912
*/
10-
const TitleCaseConversion = (inputString) => {
13+
const titleCaseConversion = (inputString) => {
14+
if (inputString === '') return ''
1115
// Extract all space separated string.
1216
const stringCollections = inputString.split(' ').map(word => {
1317
let firstChar = ''
14-
// Get a character code by the use charCodeAt method.
18+
// Get the [ASCII](https://en.wikipedia.org/wiki/ASCII) character code by the use charCodeAt method.
1519
const firstCharCode = word[0].charCodeAt()
16-
// If the character code lies between 97 to 122 it means they are in the lower case so convert it.
20+
// If the ASCII character code lies between 97 to 122 it means they are in the lowercase so convert it.
1721
if (firstCharCode >= 97 && firstCharCode <= 122) {
1822
// Convert the case by use of the above explanation.
1923
firstChar += String.fromCharCode(firstCharCode - 32)
@@ -22,21 +26,21 @@ const TitleCaseConversion = (inputString) => {
2226
firstChar += word[0]
2327
}
2428
const newWordChar = word.slice(1).split('').map(char => {
25-
// Get a character code by the use charCodeAt method.
29+
// Get the ASCII character code by the use charCodeAt method.
2630
const presentCharCode = char.charCodeAt()
27-
// If the character code lies between 65 to 90 it means they are in the upper case so convert it.
31+
// If the ASCII character code lies between 65 to 90, it means they are in the uppercase so convert it.
2832
if (presentCharCode >= 65 && presentCharCode <= 90) {
2933
// Convert the case by use of the above explanation.
3034
return String.fromCharCode(presentCharCode + 32)
3135
}
3236
// Else return the characters without any modification.
3337
return char
3438
})
35-
// return the first converted character and remaining character string.
39+
// Return the first converted character and remaining character string.
3640
return firstChar + newWordChar.join('')
3741
})
38-
// convert all words in a string and return it.
42+
// Convert all words in a string and return it.
3943
return stringCollections.join(' ')
4044
}
4145

42-
module.exports = TitleCaseConversion
46+
export { titleCaseConversion }
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { titleCaseConversion } from '../TitleCaseConversion'
2+
3+
describe(('Tests for the titleCaseConversion function'), () => {
4+
it('should return an empty string when the input is an empty string', () => {
5+
expect(titleCaseConversion('')).toEqual('')
6+
})
7+
8+
it('should return the input string when the input string is a title case string', () => {
9+
expect(titleCaseConversion('A Proper Title Case String')).toEqual('A Proper Title Case String')
10+
})
11+
12+
it('should return a title case string when input is an all-uppercase string', () => {
13+
expect(titleCaseConversion('ALL UPPER CASE')).toEqual('All Upper Case')
14+
})
15+
16+
it('should return a title case string when input is a title case string of with spaces', () => {
17+
expect(titleCaseConversion('ALL UPPERCASE')).toEqual('All Uppercase')
18+
})
19+
20+
it('should return a title case string when input is a title case string of with no spaces', () => {
21+
expect(titleCaseConversion('ALLUPPERCASE')).toEqual('Alluppercase')
22+
})
23+
24+
it('should return a title case string when input is a title case string with punctuation', () => {
25+
expect(titleCaseConversion('All Title Case!')).toEqual('All Title Case!')
26+
})
27+
28+
it('should return a title case string when input is an all-lowercase string with no spaces', () => {
29+
expect(titleCaseConversion('lowercaseinput')).toEqual('Lowercaseinput')
30+
})
31+
32+
it('should return a title case string when input is an all-lowercase string with spaces', () => {
33+
expect(titleCaseConversion('lowercase input')).toEqual('Lowercase Input')
34+
})
35+
36+
it('should return a title case string when input is an all-lowercase string with punctuation', () => {
37+
expect(titleCaseConversion('lower, case, input.')).toEqual('Lower, Case, Input.')
38+
})
39+
40+
it('should return a title case string when input is an mixed-case string', () => {
41+
expect(titleCaseConversion('mixeD CaSe INPuT')).toEqual('Mixed Case Input')
42+
})
43+
44+
it('should return a title case string when input is an mixed-case string with no spaces', () => {
45+
expect(titleCaseConversion('mixeDCaSeINPuT')).toEqual('Mixedcaseinput')
46+
})
47+
48+
it('should return a title case string when input is an mixed-case string with punctuation', () => {
49+
expect(titleCaseConversion('mixeD, CaSe, INPuT!')).toEqual('Mixed, Case, Input!')
50+
})
51+
})

DIRECTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* test
5757
* [DecimalToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToHex.test.js)
5858
* [DecimalToRoman](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToRoman.test.js)
59+
* [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/TitleCaseConversion.test.js)
5960
* [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/TitleCaseConversion.js)
6061
* [UpperCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/UpperCaseConversion.js)
6162

Data-Structures/Tree/Trie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Trie.prototype.remove = function (word, count) {
8787
// if the object forms some other objects prefix we dont delete it
8888
// For checking an empty object
8989
// https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
90-
if (child.count <= 0 && (Object.keys(child.children).length && child.childre.constructor === Object)) {
90+
if (child.count <= 0 && (Object.keys(child.children).length && child.children.constructor === Object)) {
9191
child.parent.children[child.key] = undefined
9292
}
9393
}

Dynamic-Programming/SudokuSolver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ const isValid = (board, row, col, k) => {
2121
return true
2222
}
2323

24-
const sodokoSolver = (data) => {
24+
const sudokuSolver = (data) => {
2525
for (let i = 0; i < 9; i++) {
2626
for (let j = 0; j < 9; j++) {
2727
if (data[i][j] === '.') {
2828
for (let k = 1; k <= 9; k++) {
2929
if (isValid(data, i, j, k)) {
3030
data[i][j] = `${k}`
31-
if (sodokoSolver(data)) {
31+
if (sudokuSolver(data)) {
3232
return true
3333
} else {
3434
data[i][j] = '.'
@@ -44,7 +44,7 @@ const sodokoSolver = (data) => {
4444

4545
// testing
4646
(() => {
47-
if (sodokoSolver(_board)) {
47+
if (sudokuSolver(_board)) {
4848
console.log(_board)
4949
}
5050
})()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ See our [directory](DIRECTORY.md).
2525

2626
## Algorithm Explanation
2727

28-
see our [wiki](https://github.com/TheAlgorithms/Javascript/wiki)
28+
See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki).

0 commit comments

Comments
 (0)