@pelevesque/is-palindrome
v0.0.8
Published
Checks if a string is a palindrome with a grouping feature not seen in other palindrome checkers.
Downloads
22
Readme
is-palindrome
Checks if a string is a palindrome with a grouping feature not seen in other palindrome checkers.
Node Repository
https://www.npmjs.com/package/@pelevesque/is-palindrome
Installation
npm install @pelevesque/is-palindrome
Tests
Command | Description
---------------------------- | ------------
npm test
or npm run test
| All Tests Below
npm run cover
| Standard Style
npm run standard
| Coverage
npm run unit
| Unit Tests
Usage
Parameters
str (required)
groupBy (optional) default = 1
pivotMustBePalindromic (optional) default = false
Examples
const isPalindrome = require('@pelevesque/is-palindrome')
// works with traditional palindromes
isPalindrome('') // false
isPalindrome('12345') // false
isPalindrome('a') // true
isPalindrome('1221') // true
isPalindrome('12321') // true
// a groupBy parameter can be used to group elements
const groupBy = 2
isPalindrome('abba', groupBy) // false
isPalindrome('abab', groupBy) // true
isPalindrome('abcba', groupBy) // true
// pivots do not have to be palindromic by default
// they exist when a center point is smaller than groupBy * 2
const groupBy = 4
isPalindrome('abcd!@#$123!@#$abcd', groupBy) // true
isPalindrome('abcd!@#$1234!@#$abcd', groupBy) // true
isPalindrome('abcd!@#$12345!@#$abcd', groupBy) // true
isPalindrome('abcd!@#$12321!@#$abcd', groupBy) // true
// the pivotMustBePalindromic flag can be used to force palindromic pivots
const groupBy = 4
const pivotMustBePalindromic = true
isPalindrome('abcd!@#$12345!@#$abcd', groupBy, pivotMustBePalindromic) // false
isPalindrome('abcd!@#$12321!@#$abcd', groupBy, pivotMustBePalindromic) // true