mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 11:08:54 +08:00
fixed some spellings
This commit is contained in:
@ -14,24 +14,24 @@ const AlternativeStringArrange = (str1, str2) => {
|
||||
return 'Not string(s)'
|
||||
}
|
||||
|
||||
// output string vlaue.
|
||||
// output string value.
|
||||
let outStr = ''
|
||||
|
||||
// get first string length.
|
||||
const firstStringLength = str1.length
|
||||
// get second string length.
|
||||
const secondStringLength = str2.length
|
||||
// absolute length for oparetion.
|
||||
const absLenght = firstStringLength > secondStringLength ? firstStringLength : secondStringLength
|
||||
// absolute length for operation.
|
||||
const absLength = firstStringLength > secondStringLength ? firstStringLength : secondStringLength
|
||||
|
||||
// Iterate the character count until the absolute count is reached.
|
||||
for (let charCount = 0; charCount < absLenght; charCount++) {
|
||||
// If firstStringLength is lesser than the charCount it means they are able to re-arange.
|
||||
for (let charCount = 0; charCount < absLength; charCount++) {
|
||||
// If firstStringLength is lesser than the charCount it means they are able to re-arrange.
|
||||
if (charCount < firstStringLength) {
|
||||
outStr += str1[charCount]
|
||||
}
|
||||
|
||||
// If secondStringLength is lesser than the charCount it means they are able to re-arange.
|
||||
// If secondStringLength is lesser than the charCount it means they are able to re-arrange.
|
||||
if (charCount < secondStringLength) {
|
||||
outStr += str2[charCount]
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ const checkPalindrome = (str) => {
|
||||
if (str.length === 0) {
|
||||
return 'Empty string'
|
||||
}
|
||||
// Reverse only works with array, thus conevert the string to array, reverse it and convert back to string
|
||||
// Reverse only works with array, thus convert the string to array, reverse it and convert back to string
|
||||
// return as palindrome if the reversed string is equal to the input string
|
||||
const reversed = [...str].reverse().join('')
|
||||
return str === reversed ? 'Palindrome' : 'Not a Palindrome'
|
||||
|
@ -15,12 +15,12 @@ const levenshteinDistance = (a, b) => {
|
||||
.fill(null)
|
||||
.map(() => Array(a.length + 1).fill(null))
|
||||
|
||||
// Initialising first column:
|
||||
// Initializing first column:
|
||||
for (let i = 0; i <= a.length; i += 1) {
|
||||
distanceMatrix[0][i] = i
|
||||
}
|
||||
|
||||
// Initialising first row:
|
||||
// Initializing first row:
|
||||
for (let j = 0; j <= b.length; j += 1) {
|
||||
distanceMatrix[j][0] = j
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
// Given a sentence, return the most occuring word
|
||||
// Given a sentence, return the most occurring word
|
||||
|
||||
/**
|
||||
* @param {string} sentence - the sentence you want to find the most occuring word
|
||||
* @returns {string} - the most occuring word
|
||||
* @param {string} sentence - the sentence you want to find the most occurring word
|
||||
* @returns {string} - the most occurring word
|
||||
*
|
||||
* @example
|
||||
* - maxWord('lala lili lala'); // lala
|
||||
*/
|
||||
const maxWord = (sentence = '') => {
|
||||
if (typeof sentence !== 'string') {
|
||||
throw new TypeError('the param sould be string')
|
||||
throw new TypeError('the param should be string')
|
||||
}
|
||||
|
||||
if (!sentence) {
|
||||
|
@ -6,7 +6,7 @@ describe('Testing the maxWord function', () => {
|
||||
})
|
||||
it('get the max word', () => {
|
||||
const string = 'ba ba ba ba banana'
|
||||
const mostOccuringWord = maxWord(string)
|
||||
expect(mostOccuringWord).toBe('ba')
|
||||
const mostOccurringWord = maxWord(string)
|
||||
expect(mostOccurringWord).toBe('ba')
|
||||
})
|
||||
})
|
||||
|
@ -18,7 +18,7 @@ describe('checkIfPatternExists', () => {
|
||||
const SUT = checkIfPatternExists(text, pattern)
|
||||
expect(SUT).toBe(undefined)
|
||||
})
|
||||
it('expects to throw an error message when given inpuut is not a string', () => {
|
||||
it('expects to throw an error message when given input is not a string', () => {
|
||||
const text = 123444456
|
||||
const pattern = 123
|
||||
expect(() => checkIfPatternExists(text, pattern)).toThrow(
|
||||
|
Reference in New Issue
Block a user