palindrome-solver

1.0.4 • Public • Published

Palindrome-solver

Get every possible palindrome within a word

Example

var PSolver = require('palindrome-solver');
 
var word = "anna";
 
var solver = new PSolver();
 
solver.palindromes(word, function(answer) {
  //answer is an array
  console.log(answer.type, '('+ answer.result.length +')-->', answer.result);
});
 
// palindromes run time: 0ms
//
// palindromes (4)--> [ 'ana', 'nan', 'anna', 'naan' ]
 
solver.combinations(word, function(answer) {
  //answer is an array
  console.log(answer.type, '('+ answer.result.length +')-->', answer.result);
});
 
// combinations run time: 0ms
//
// combinations (18)-->
// [ 'a',
//   'n',
//   'an',
//   'aa',
//   'na',
//   'nn',
//   'ann',
//   'ana',
//   'aan',
//   'nan',
//   'naa',
//   'nna',
//   'anna',
//   'anan',
//   'aann',
//   'nana',
//   'naan',
//   'nnaa' ]
 
 

Performance

Finding all permutations of a word is O(n!) where n is the number of characters in the word. You've been warned.

Combinations

Only unique combinations are returned. Max possible combinations is N!.

Package Sidebar

Install

npm i palindrome-solver

Weekly Downloads

3

Version

1.0.4

License

MIT

Last publish

Collaborators

  • gmturbo