Removes and returns palindromes from an array.
https://www.npmjs.com/package/@pelevesque/remove-palindromes
npm install @pelevesque/remove-palindromes
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 |
arr (required)
options (optional) default = { groupBy: 1, pivotMustBePalindromic: false, remove: true }
const removePalindromes = require('@pelevesque/remove-palindromes')
const arr = [
'12321',
'abcdef',
'1221',
'aaaaa'
]
const palindromes = removePalindromes(arr)
/*
arr = [
'abcdef'
]
palindromes = [
'12321',
'1221',
'aaaaa'
]
*/
const arr = [
'aaabbb12bbbaaa',
'123bbb321',
'12321',
'12345',
'123bcdbcd123',
'123ccc123',
'abcdef',
'123aaa343aaa123'
]
const opts = { groupBy: 3 }
const palindromes = removePalindromes(arr, opts)
/*
arr = [
'123bbb321',
'12321',
'12345',
'abcdef'
]
palindromes = [
'aaabbb12bbbaaa',
'123bcdbcd123',
'123ccc123',
'123aaa343aaa123'
]
*/
const arr = [
'aaabbb12bbbaaa',
'123bbb321',
'12321',
'12345',
'123bcdbcd123',
'123ccc123',
'abcdef',
'123aaa343aaa123'
]
const opts = { groupBy: 3, pivotMustBePalindromic: true }
const palindromes = removePalindromes(arr, opts)
/*
arr = [
'aaabbb12bbbaaa',
'123bbb321',
'12321',
'12345',
'abcdef'
]
palindromes = [
'123bcdbcd123',
'123ccc123',
'123aaa343aaa123'
]
*/
With the remove option set to false, palindromes are still returned, but nothing is removed from the original array.
const arr = [
'aaabbb12bbbaaa',
'123bbb321',
'12321',
'12345',
'123bcdbcd123',
'123ccc123',
'abcdef',
'123aaa343aaa123'
]
const opts = { groupBy: 3, pivotMustBePalindromic: true, remove: false }
const palindromes = removePalindromes(arr, opts)
/*
arr = [
'aaabbb12bbbaaa',
'123bbb321',
'12321',
'12345',
'123bcdbcd123',
'123ccc123',
'abcdef',
'123aaa343aaa123'
]
palindromes = [
'123bcdbcd123',
'123ccc123',
'123aaa343aaa123'
]
*/