@pelevesque/swap-substrings
v1.0.3
Published
Swaps substrings.
Downloads
5
Readme
swap-substrings
Swaps substrings.
Node Repository
https://www.npmjs.com/package/@pelevesque/swap-substrings
Installation
npm install @pelevesque/swap-substrings
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
Requiring
const swapSubstrings = require('@pelevesque/swap-substrings')
Swap Substrings
const str = 'bad bed led lad'
const swaps = ['a', 'e']
const result = swapSubstrings(str, swaps)
// result === 'bed bad lad led'
const str = 'dog treats for dogs, cat treats for cats'
const swaps = ['dog', 'cat']
const result = swapSubstrings(str, swaps)
// result === 'cat treats for cats, dog treats for dogs'
Swap Many Substring Pairs
const str = 'a fairly large man says oh oh oh to the bird'
const swaps = [
['a ', 'the '],
['man', 'bird'],
['large', 'small'],
['oh', 'tweet']
]
const result = swapSubstrings(str, swaps)
// result === 'the fairly small bird says tweet tweet tweet to a man'
Substitute Substrings (Replacement is not in the String)
const str = 'I like hamsters'
const swaps = ['hamsters', 'squirrels']
const result = swapSubstrings(str, swaps)
// result === 'I like squirrels'