@pelevesque/remove-anagrams

0.0.3 • Public • Published

Build Status Coverage Status JavaScript Style Guide

remove-anagrams

Removes and returns anagrams from an array.

Node Repository

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

Installation

npm install @pelevesque/remove-anagrams

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, canonicalize: false, substringsToIgnore: [],  remove: true }

Requiring

const removeAnagrams = require('@pelevesque/remove-anagrams')

Basic

const arr = [
  '12345',
  'elvis',
  'lives', // 1
  '34251', // 0
  'silve', // 1
  '!@#$%',
  '%$#@!' // 5
]
const anagrams = removeAnagrams(arr)
/*
arr = [
  '12345',
  'elvis',
  '!@#$%'
]
anagrams = [
  'lives',
  '34251',
  'silve',
  '%$#@!'
]
*/

Grouping by Length Option

const arr = [
  '123abc456',
  'abc456123', // 0
  'a1b2c3456',
  '456def789gh',
  '789ghdef456', // 3
  '4g5hdef6789'
]
const opts = { groupBy: 3 }
const anagrams = removeAnagrams(arr, opts)
/*
arr = [
  '123abc456',
  'a1b2c3456',
  '456def789gh',
  '4g5hdef6789'
]
anagrams = [
  'abc456123',
  '789ghdef456'
]
*/

Explicit Grouping Option

const arr = [
  '22boy321j',
  'j321boy22', // 0
  'aabbccdd',
  'boy22321j', // 0
  '22boy321j', // 0
  'b2o2y3j21',
  'aabbccdd',
  'ccbbaadd'
]
const opts = { groupBy: ['22', 'boy', '321', 'j'] }
const anagrams = removeAnagrams(arr, opts)
/*
arr = [
  '22boy321j',
  'aabbccdd',
  'b2o2y3j21',
  'aabbccdd',
  'ccbbaadd'
]
anagrams = [
  'j321boy22',
  'boy22321j',
  '22boy321j'
]
*/

Canonicalize Option

const arr = [
  'ElviS',
  'lives', // 0
  'AmwÉ',
  'earnw' // 2
]
const opts = { canonicalize: true }
const anagrams = removeAnagrams(arr, opts)
/*
arr = [
  'ElviS',
  'AmwÉ'
]
anagrams = [
  'lives',
  'earnw'
]
*/

Substrings To Ignore Option

const arr = [
  'christmas tree',
  'search, set, trim', // 0
  'christmastree', // 0
  'elvis',
  'lives' // 3
]
const opts = { substringsToIgnore: [' ', ','] }
const anagrams = removeAnagrams(arr, opts)
/*
arr = [
  'christmas tree',
  'elvis'
]
anagrams = [
  'search, set, trim',
  'christmastree',
  'lives'
]
*/

Remove Option

const arr = [
  'elvis',
  'lives', // 0
  'aabbcc',
  'aabbcc', // 2
  'ccbbaa' // 2
]
const opts = { remove: false }
const anagrams = removeAnagrams(arr, opts)
/*
arr = [
  'elvis',
  'lives',
  'aabbcc',
  'aabbcc',
  'ccbbaa'
]
anagrams = [
  'lives',
  'aabbcc',
  'ccbbaa'
]
*/

Readme

Keywords

Package Sidebar

Install

npm i @pelevesque/remove-anagrams

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

11.1 kB

Total Files

6

Last publish

Collaborators

  • pelevesque