Return anagram words if existed from the given string
Return anagram words if existed from the given pattern. Check if two strings are anagram. Check if the given word is palindrome.
It has npm package here called anagram-words
npm i anagram-words
const anagramWords = require("anagram-words")
// findPattern
console.log(anagramWords.findPattern("car", "race car care")) // output: [ 'rac', 'car', 'arc', 'rca', 'car' ]
console.log(anagramWords.findPattern("car", "race car care", {unique: true})) // output: [ 'rac', 'car', 'arc', 'rca' ]
console.log(anagramWords.findPattern("car", "race car care", {space: true})) // output: [ 'rac', 'car', 'car' ]
console.log(anagramWords.findPattern("car", "race car care", {space: true, unique: true})) // output: [ 'rac', 'car' ]
console.log(anagramWords.findPattern("cAr", "race car cAre", {caseSensitive: true})) // output: [ 'rcA', 'cAr' ]
// areAnagram
console.log(anagramWords.areAnagram("mything", "My night")) // output: true
console.log(anagramWords.areAnagram("mything", "My night", {space: true})) // output: false
console.log(anagramWords.areAnagram("Thing", "Night", {caseSensitive: true})) // output: false
console.log(anagramWords.areAnagram("My thing", "My night", {caseSensitive: true, space: true})) // output: true
console.log(anagramWords.areAnagram("Mything", "My Night", {caseSensitive: true, space: true})) // output: false
// isPalindrome
console.log(anagramWords.isPalindrome("Race car")) // output: true
console.log(anagramWords.isPalindrome("Racecar", {caseSensitive: true})) // output: false
console.log(anagramWords.isPalindrome("race car", {space: true})) // output: false
console.log(anagramWords.isPalindrome("Rac e caR", {caseSensitive: true, space: true})) // output: true
console.log(anagramWords.isPalindrome("Race car", {caseSensitive: true, space: true})) // output: false
findPattern(pattern, text, options)
arraypattern (string) is the sequence string you look for in in the string texttext (string) is the whole string you want to look for the patternoptions (object) is an object to customize the options desribed bellow:
| Parameter | Type | Deafult | Description |
| ——— | :—-: | :——-: | ———– |
| space | boolean | false | true means space counted as a character.false means space is not counted as character and will be ignored |
| caseSensitive | boolean | false | true means case sensitive character.false means case insensitive |
| unique | boolean | false | true only return unique sequence result.false will return all sequence result | const anagramWords = require("anagram-words")
console.log(anagramWords.findPattern("car", "race car care", {space: true, unique: true})) // output: [ 'rac', 'car' ]
areAnagram(word1, word2, options)
boolean. true if they are anagram, false if it is not anagramword1 and word2 is the text/string you you want to check wether if they are anagram or notoptions (object) is an object to customize the options desribed bellow:
| Parameter | Type | Deafult | Description |
| ——— | :—-: | :——-: | ———– |
| space | boolean | false | true means space counted as a character.false means space is not counted as character and will be ignored |
| caseSensitive | boolean | false | true means case sensitive character.false means case insensitive | const anagramWords = require("anagram-words")
console.log(anagramWords.areAnagram("Thing", "Night", {caseSensitive: true})) // output: false
console.log(anagramWords.areAnagram("Thing", "Night")) // output: true
isPalindrome(word, options)
boolean. true if the word palindrome, false if it is not palindromeword is the text/string you you want to check if it is palindrome or notoptions (object) is an object to customize the options desribed bellow:
| Parameter | Type | Deafult | Description |
| ——— | :—-: | :——-: | ———– |
| space | boolean | false | true means space counted as a character.false means space is not counted as character and will be ignored |
| caseSensitive | boolean | false | true means case sensitive character.false means case insensitive | const anagramWords = require("anagram-words")
console.log(anagramWords.isPalindrome("Race car")) // output: true
console.log(anagramWords.isPalindrome("Racecar", {caseSensitive: true})) // output: false
console.log(anagramWords.isPalindrome("race car", {space: true})) // output: false