-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdef186
commit f02a277
Showing
1 changed file
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
function checkStringLength (string, maxLength) { | ||
const currentLength = string.length; | ||
|
||
if (currentLength <= maxLength) { | ||
const checkStringLength = (string, maxLength) => { | ||
if (string.length <= maxLength) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
}; | ||
|
||
function checkPalindrome (str) { | ||
const normalizedString = str.toLowerCase().replaceAll(' ', ''); | ||
const checkPalindrome = (string) => { | ||
const normalizedString = string.toLowerCase().replaceAll(' ', ''); | ||
let newString = ''; | ||
const currentLength = normalizedString.length; | ||
|
||
for (let currentIndex = currentLength - 1; currentIndex >= 0; currentIndex--) { | ||
let currentSymbol = normalizedString[currentIndex]; | ||
newString += currentSymbol; | ||
for (let currentIndex = normalizedString.length - 1; currentIndex >= 0; currentIndex--) { | ||
newString += normalizedString[currentIndex]; | ||
} | ||
|
||
return newString === normalizedString; | ||
}; | ||
|
||
const getNumbers = (string) => { | ||
let result = ''; | ||
string = string.toString(); | ||
|
||
for (let i = 0; i <= string.length - 1; i++) { | ||
if (Number.isNaN(parseInt(string[i], 10)) === false) { | ||
result += string[i]; | ||
} | ||
} | ||
|
||
return(newString === normalizedString); | ||
} | ||
return result === '' ? NaN : parseInt(result, 10); | ||
}; |