Skip to content

pelevesque-node/remove-palindromes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status JavaScript Style Guide

remove-palindromes

Removes and returns palindromes from an array.

Node Repository

https://www.npmjs.com/package/@pelevesque/remove-palindromes

Installation

npm install @pelevesque/remove-palindromes

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

arr     (required)
options (optional) default = { groupBy: 1, pivotMustBePalindromic: false, remove: true }

Requiring

const removePalindromes = require('@pelevesque/remove-palindromes')

Basic

const arr = [
  '12321',
  'abcdef',
  '1221',
  'aaaaa'
]
const palindromes = removePalindromes(arr)
/*
arr = [
  'abcdef'
]
palindromes = [
  '12321',
  '1221',
  'aaaaa'
]
*/

GroupBy Option

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'
]
*/

PivotMustBePalindromic Option

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'
]
*/

Remove Option

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'
]
*/

About

Removes and returns palindromes from an array.

Resources

License

Stars

Watchers

Forks

Packages

No packages published