Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding JSDOCS for the following files BoyerMoore checkRearrangedPalin… #1650

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading