mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
Added tests for Strings algorithms (#390)
* test: added tests for check anagram function
This commit is contained in:
@ -8,6 +8,9 @@ return the starting index if the given pattern is
|
||||
available in the text
|
||||
*/
|
||||
const checkIfPatternExists = (text, pattern) => {
|
||||
if (typeof text !== 'string' || typeof pattern !== 'string') {
|
||||
throw new TypeError('Given input is not a string')
|
||||
}
|
||||
const textLength = text.length // Store the length of the text in a variable
|
||||
const patternLength = pattern.length // Store the length of the pattern in a variable
|
||||
|
||||
@ -22,15 +25,10 @@ const checkIfPatternExists = (text, pattern) => {
|
||||
// j + 1 is equal to the length of the pattern
|
||||
if (j + 1 === patternLength) {
|
||||
console.log(`Given pattern is found at index ${i}`)
|
||||
return `Given pattern is found at index ${i}`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const main = () => {
|
||||
const text = 'AABAACAADAABAAAABAA'
|
||||
const pattern = 'AABA'
|
||||
checkIfPatternExists(text.toLowerCase(), pattern.toLowerCase())
|
||||
}
|
||||
|
||||
main()
|
||||
export { checkIfPatternExists }
|
||||
|
Reference in New Issue
Block a user