https://github.com/btoo/dat-palindrome-doe
determine if given string is a palindrome or not (without using any cheating methods like replace or reverse because they're inefficient); allows for custom configs
https://github.com/btoo/dat-palindrome-doe
Last synced: 7 months ago
JSON representation
determine if given string is a palindrome or not (without using any cheating methods like replace or reverse because they're inefficient); allows for custom configs
- Host: GitHub
- URL: https://github.com/btoo/dat-palindrome-doe
- Owner: btoo
- Created: 2017-12-09T03:22:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-09T17:33:57.000Z (over 8 years ago)
- Last Synced: 2025-01-25T21:15:07.761Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dat-palindrome-doe
determine if given string is a palindrome or not
configure the algorithm with custom options. the default configuration is this (merged with custom configs when provided)
```js
const defaultConfig = {
// first deal with special cases (assessed before validation of input)
specialIs: value => value === 0 || value === '',
specialIsNot: value => !value || value === true,
// then validate input
validateInput: value => typeof value === "string" || typeof value === "number",
// algorithm functions
filter: char => /^[a-z0-9]+$/i.test(char), // isAlphaNumeric
compare: (a, b) => !!a && !!b && a.toLowerCase() === b.toLowerCase(), // leftEqualsRightWhenBothLowercase
}
```
usage with default configs
```js
const isPalidrome = require('dat-palindrome-doe')()
console.log(isPalindrome('abcd_DCBA')) // true
```
usage with custom configs (case-senstitive comparator)
```js
const isPalidrome = require('dat-palindrome-doe')({
compare: (a, b) => !!a && !!b && a === b
})
console.log(isPalindrome('abcd_DCBA')) // false
```