diff --git a/String/BoyerMoore.js b/String/BoyerMoore.js index 6ec8108b71..542b3cace2 100644 --- a/String/BoyerMoore.js +++ b/String/BoyerMoore.js @@ -1,14 +1,14 @@ -/* - * - * - *Implementation of the Boyer-Moore String Search Algorithm. - *The Boyer–Moore string search algorithm allows linear time in - *search by skipping indices when searching inside a string for a pattern. - * - * - * - * - **/ +/** + * Implementation of the Boyer-Moore String Search Algorithm. + * The Boyer–Moore string search algorithm allows linear time search by skipping indices + * when searching inside a string for a pattern. + */ + +/** + * Builds the bad match table for the Boyer-Moore algorithm based on the pattern. + * @param {string} str The pattern string for which the bad match table is built. + * @returns {Object} The bad match table object containing characters and their corresponding offsets. + */ const buildBadMatchTable = (str) => { const tableObj = {} const strLength = str.length @@ -21,6 +21,12 @@ const buildBadMatchTable = (str) => { return tableObj } +/** + * Performs the Boyer-Moore string search algorithm to find a pattern in a given string. + * @param {string} str The string in which to search for the pattern. + * @param {string} pattern The pattern string to search for in the main string. + * @returns {number} The index at which the pattern is found in the string, or -1 if not found. + */ const boyerMoore = (str, pattern) => { const badMatchTable = buildBadMatchTable(pattern) let offset = 0 @@ -46,4 +52,5 @@ const boyerMoore = (str, pattern) => { } return -1 } + export { boyerMoore } diff --git a/String/CheckPalindrome.js b/String/CheckPalindrome.js index a717ccd5f4..e904f136c7 100644 --- a/String/CheckPalindrome.js +++ b/String/CheckPalindrome.js @@ -1,5 +1,11 @@ -// Palindrome check is case sensitive; i.e. Aba is not a palindrome -// input is a string +/** + * Checks if a string is a palindrome. + * A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. + * Palindrome check is case sensitive; i.e., "Aba" is not considered a palindrome. + * @param {string} str The input string to be checked for palindrome. + * @returns {string} Returns 'Palindrome' if the input string is a palindrome, + * 'Not a Palindrome' if it is not, or an error message if the input is not a valid string. + */ const checkPalindrome = (str) => { // check that input is a string if (typeof str !== 'string') { diff --git a/String/CheckRearrangePalindrome.js b/String/CheckRearrangePalindrome.js index c3feb59f16..54b28133bb 100644 --- a/String/CheckRearrangePalindrome.js +++ b/String/CheckRearrangePalindrome.js @@ -3,7 +3,9 @@ * Receives a string and returns whether it can be rearranged to become a palindrome or not * The string can only be a palindrome if the count of ALL characters is even or if the ONLY ONE character count is odd * Input is a string - * + * @param {string} str The input string to be checked for palindrome rearrangement. + * @returns {boolean|string} Returns true if the string can be rearranged to form a palindrome, + * false if it cannot, or an error message if the input is not a valid string. **/ export const palindromeRearranging = (str) => {