Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fixing-string-folder-JSDOCS' int…
Browse files Browse the repository at this point in the history
…o fix-jsdocs
  • Loading branch information
mohmmadAyesh committed Mar 27, 2024
2 parents 8f10dee + 575eead commit de118c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
29 changes: 18 additions & 11 deletions String/BoyerMoore.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -46,4 +52,5 @@ const boyerMoore = (str, pattern) => {
}
return -1
}

export { boyerMoore }
10 changes: 8 additions & 2 deletions String/CheckPalindrome.js
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
4 changes: 3 additions & 1 deletion String/CheckRearrangePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit de118c6

Please sign in to comment.