From 7a70ed789cd78fd596c51fb39998c1d5c90f7d6b Mon Sep 17 00:00:00 2001 From: Dev <60340125+ayazshah2@users.noreply.github.com> Date: Mon, 4 Oct 2021 11:26:14 +0400 Subject: [PATCH 01/10] capitalize first letter --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a44b38c5..384c8f625 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ See our [directory](DIRECTORY.md). ## Algorithm Explanation -see our [wiki](https://github.com/TheAlgorithms/Javascript/wiki) +See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki) From 90a59e6b60f5cec6e5e34c3b5884a51c4e02c736 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:52:10 -0400 Subject: [PATCH 02/10] Update function name casing to match convention --- Conversions/TitleCaseConversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 2db9620ea..85aea1c2a 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -7,7 +7,7 @@ * @param {String} inputString input string * @returns {String} */ -const TitleCaseConversion = (inputString) => { +const titleCaseConversion = (inputString) => { // Extact all space seprated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' From 4ea13dee13b8f8bcfe9e4bc5d977f9d01b6a2c60 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:52:30 -0400 Subject: [PATCH 03/10] Update export style for Jest testing --- Conversions/TitleCaseConversion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 85aea1c2a..65994a9fc 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -39,4 +39,4 @@ const titleCaseConversion = (inputString) => { return stringCollections.join(' ') } -module.exports = TitleCaseConversion +export { titleCaseConversion } From 4ab047ddc54627df9853d1886abecc71d7b42a98 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:53:19 -0400 Subject: [PATCH 04/10] Fix typos and add ASCII link --- Conversions/TitleCaseConversion.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 65994a9fc..9013cc924 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -3,17 +3,17 @@ */ /** - * The TitleCaseConversion converts a string into a title case string. - * @param {String} inputString input string - * @returns {String} + * The titleCaseConversion function converts a string into a title case string. + * @param {string} inputString The input string which can have any types of letter casing. + * @returns {string} A string that is in title case. */ const titleCaseConversion = (inputString) => { // Extact all space seprated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' - // Get a character code by the use charCodeAt method. + // Get the [ASCII](https://en.wikipedia.org/wiki/ASCII) character code by the use charCodeAt method. const firstCharCode = word[0].charCodeAt() - // If the character code lies between 97 to 122 it means they are in the lower case so convert it. + // If the ASCII character code lies between 97 to 122 it means they are in the lowercase so convert it. if (firstCharCode >= 97 && firstCharCode <= 122) { // Convert the case by use of the above explanation. firstChar += String.fromCharCode(firstCharCode - 32) @@ -22,9 +22,9 @@ const titleCaseConversion = (inputString) => { firstChar += word[0] } const newWordChar = word.slice(1).split('').map(char => { - // Get a character code by the use charCodeAt method. + // Get the ASCII character code by the use charCodeAt method. const presentCharCode = char.charCodeAt() - // If the character code lies between 65 to 90 it means they are in the upper case so convert it. + // If the ASCII character code lies between 65 to 90, it means they are in the uppercase so convert it. if (presentCharCode >= 65 && presentCharCode <= 90) { // Convert the case by use of the above explanation. return String.fromCharCode(presentCharCode + 32) @@ -32,10 +32,10 @@ const titleCaseConversion = (inputString) => { // Else return the characters without any modification. return char }) - // return the first converted character and remaining character string. + // Return the first converted character and remaining character string. return firstChar + newWordChar.join('') }) - // convert all words in a string and return it. + // Convert all words in a string and return it. return stringCollections.join(' ') } From 184814745ed4c75b66621356595db0907ad66845 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 09:56:32 -0400 Subject: [PATCH 05/10] Update description/documentation with explanation of title case, and simplifying assumptions this function makes --- Conversions/TitleCaseConversion.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 9013cc924..72ba26299 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -1,5 +1,8 @@ /* - Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl + Problem statement and Explanation : https://www.codeproject.com/Tips/162540/Letter-Case-Conversion-Algorithms-Title-Case-Toggl. + [Title case](https://en.wikipedia.org/wiki/Title_case) is a style where all words are capitalized. Officially, title case + does not capitalize some words, such as very short words like "a" or "is", but for the purposes of this function, a general approach + is taken where all words are capitalized regarless of length. */ /** From 654c824fdd63385a9476808d495533bfe8a233f3 Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 12:21:34 -0400 Subject: [PATCH 06/10] Add check to handle empty string input. Could throw an error instead, but to be consistent with other case conversion functions in this collection, it returns an empty string when input is empty string. --- Conversions/TitleCaseConversion.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Conversions/TitleCaseConversion.js b/Conversions/TitleCaseConversion.js index 72ba26299..44967d124 100644 --- a/Conversions/TitleCaseConversion.js +++ b/Conversions/TitleCaseConversion.js @@ -11,6 +11,7 @@ * @returns {string} A string that is in title case. */ const titleCaseConversion = (inputString) => { + if (inputString === '') return '' // Extact all space seprated string. const stringCollections = inputString.split(' ').map(word => { let firstChar = '' From ced6c891a62064b0e787b95c28565ebacb5f9e2d Mon Sep 17 00:00:00 2001 From: Charlie Moore Date: Mon, 4 Oct 2021 12:23:05 -0400 Subject: [PATCH 07/10] Add tests for titleCaseConversion function --- Conversions/test/TitleCaseConversion.test.js | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Conversions/test/TitleCaseConversion.test.js diff --git a/Conversions/test/TitleCaseConversion.test.js b/Conversions/test/TitleCaseConversion.test.js new file mode 100644 index 000000000..a4eaa2ecd --- /dev/null +++ b/Conversions/test/TitleCaseConversion.test.js @@ -0,0 +1,51 @@ +import { titleCaseConversion } from '../TitleCaseConversion' + +describe(('Tests for the titleCaseConversion function'), () => { + it('should return an empty string when the input is an empty string', () => { + expect(titleCaseConversion('')).toEqual('') + }) + + it('should return the input string when the input string is a title case string', () => { + expect(titleCaseConversion('A Proper Title Case String')).toEqual('A Proper Title Case String') + }) + + it('should return a title case string when input is an all-uppercase string', () => { + expect(titleCaseConversion('ALL UPPER CASE')).toEqual('All Upper Case') + }) + + it('should return a title case string when input is a title case string of with spaces', () => { + expect(titleCaseConversion('ALL UPPERCASE')).toEqual('All Uppercase') + }) + + it('should return a title case string when input is a title case string of with no spaces', () => { + expect(titleCaseConversion('ALLUPPERCASE')).toEqual('Alluppercase') + }) + + it('should return a title case string when input is a title case string with punctuation', () => { + expect(titleCaseConversion('All Title Case!')).toEqual('All Title Case!') + }) + + it('should return a title case string when input is an all-lowercase string with no spaces', () => { + expect(titleCaseConversion('lowercaseinput')).toEqual('Lowercaseinput') + }) + + it('should return a title case string when input is an all-lowercase string with spaces', () => { + expect(titleCaseConversion('lowercase input')).toEqual('Lowercase Input') + }) + + it('should return a title case string when input is an all-lowercase string with punctuation', () => { + expect(titleCaseConversion('lower, case, input.')).toEqual('Lower, Case, Input.') + }) + + it('should return a title case string when input is an mixed-case string', () => { + expect(titleCaseConversion('mixeD CaSe INPuT')).toEqual('Mixed Case Input') + }) + + it('should return a title case string when input is an mixed-case string with no spaces', () => { + expect(titleCaseConversion('mixeDCaSeINPuT')).toEqual('Mixedcaseinput') + }) + + it('should return a title case string when input is an mixed-case string with punctuation', () => { + expect(titleCaseConversion('mixeD, CaSe, INPuT!')).toEqual('Mixed, Case, Input!') + }) +}) From 14034e29fe6c8bab1f6665887ab603f7c76ec76a Mon Sep 17 00:00:00 2001 From: Rak Laptudirm Date: Tue, 5 Oct 2021 12:51:04 +0530 Subject: [PATCH 08/10] chore: add punctuation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 384c8f625..3a841ce4e 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ See our [directory](DIRECTORY.md). ## Algorithm Explanation -See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki) +See our [wiki](https://github.com/TheAlgorithms/Javascript/wiki). From 1c22f65ce72036469ab99c2d397e3b2f22f558fb Mon Sep 17 00:00:00 2001 From: Keshav Bohra Date: Tue, 5 Oct 2021 12:53:38 +0530 Subject: [PATCH 09/10] fixed the issue in Trie file and typo in sudoku --- Data-Structures/Tree/Trie.js | 2 +- Dynamic-Programming/SudokuSolver.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Data-Structures/Tree/Trie.js b/Data-Structures/Tree/Trie.js index 1e00daf53..61b4f03c1 100644 --- a/Data-Structures/Tree/Trie.js +++ b/Data-Structures/Tree/Trie.js @@ -87,7 +87,7 @@ Trie.prototype.remove = function (word, count) { // if the object forms some other objects prefix we dont delete it // For checking an empty object // https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object - if (child.count <= 0 && (Object.keys(child.children).length && child.childre.constructor === Object)) { + if (child.count <= 0 && (Object.keys(child.children).length && child.children.constructor === Object)) { child.parent.children[child.key] = undefined } } diff --git a/Dynamic-Programming/SudokuSolver.js b/Dynamic-Programming/SudokuSolver.js index bbba70e7b..23e913536 100644 --- a/Dynamic-Programming/SudokuSolver.js +++ b/Dynamic-Programming/SudokuSolver.js @@ -21,14 +21,14 @@ const isValid = (board, row, col, k) => { return true } -const sodokoSolver = (data) => { +const sudokuSolver = (data) => { for (let i = 0; i < 9; i++) { for (let j = 0; j < 9; j++) { if (data[i][j] === '.') { for (let k = 1; k <= 9; k++) { if (isValid(data, i, j, k)) { data[i][j] = `${k}` - if (sodokoSolver(data)) { + if (sudokuSolver(data)) { return true } else { data[i][j] = '.' @@ -44,7 +44,7 @@ const sodokoSolver = (data) => { // testing (() => { - if (sodokoSolver(_board)) { + if (sudokuSolver(_board)) { console.log(_board) } })() From 82ad8c8ad4b6779ac27ec250de3773d418c4e599 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 5 Oct 2021 08:15:04 +0000 Subject: [PATCH 10/10] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 6ae9a6d30..26ee705cb 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -56,6 +56,7 @@ * test * [DecimalToHex](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToHex.test.js) * [DecimalToRoman](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/DecimalToRoman.test.js) + * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/test/TitleCaseConversion.test.js) * [TitleCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/TitleCaseConversion.js) * [UpperCaseConversion](https://github.com/TheAlgorithms/Javascript/blob/master/Conversions/UpperCaseConversion.js)