Added tests for Strings algorithms (#390)

* test: added tests for check anagram function
This commit is contained in:
Alexandre Xavier
2020-10-04 14:38:48 -03:00
committed by GitHub
parent e156fe36a1
commit c5fc353c32
13 changed files with 8250 additions and 22 deletions

View File

@ -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 }