Methods
# applyOptions(text, caseSensitiveopt, spaceopt) → {string|Array}
Apply options to text or array of text
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
text |
string
|
Array
|
The text you want to apply options on | ||
caseSensitive |
boolean
|
<optional> |
false | true = case sensitive. false = case insensitive. Default is false |
space |
boolean
|
<optional> |
false | true = space is count. false = space is not count as character. Default is false |
text with options applied
string
|
Array
Example
applyOptions("Race car") // 'racecar'
applyOptions(["Car", "Race car"]) // [ 'car', 'racecar' ]
applyOptions("Race car", {caseSensitive: true}) // 'Racecar'
applyOptions("Race car", {space: true}) // 'race car'
# areAnagram(word1, word2, optionsopt) → {boolean}
Check if word given are anagram
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
word1 |
string
|
First word | ||
word2 |
string
|
Second word | ||
options |
Object
|
<optional> |
Options for customization | |
caseSensitive |
boolean
|
<optional> |
false | true = case sensitive. false = case insensitive. Default is false |
space |
boolean
|
<optional> |
false | true = space is count. false = space is not count as character. Default is false |
is two words are anagram
boolean
Examples
areAnagram("mything", "My night") // true
areAnagram("Thing", "Night", {caseSensitive: true}) // false
# compare(a, b) → {boolean}
Look for same key & value from a into b. In other words, check if a is part of b
Parameters:
Name | Type | Description |
---|---|---|
a |
Object
|
Object key and value to look for |
b |
Object
|
Object key and value to look into |
true if a is part of b
boolean
Example
compare({a: 1}, {a: 1}) // true
compare({a: 1}, {a: 2}) // false
compare({a: 1}, {a: 1, b: 1}) // true
compare({a: 1}, {a: 2, b: 1}) // false
compare({a: 1}, {b: 1}) // false
# createHash(pattern, text) → {Object}
Create only fisrt hashmap of each character in pattern, text would have hashmap length as pattern hasmap length
Parameters:
Name | Type | Description |
---|---|---|
pattern |
string
|
Pattern string |
text |
string
|
Text string |
Object {pw, tw} hashmap of character as key and character count as value
Object
Example
createHash("car", "race car") // { pw: { c: 1, a: 1, r: 1 }, tw: { r: 1, a: 1, c: 1 } }
createHash("car", "eve") // { pw: { c: 1, a: 1, r: 1 }, tw: { e: 2, v: 1 } }
# findPattern(pattern, text, optionsopt) → {Array}
Return anagram words/sequences from the given string if any
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pattern |
string
|
The sequence string you look for in in the text | ||
text |
string
|
The whole string you want to look for the pattern | ||
options |
Object
|
<optional> |
Options for customization | |
caseSensitive |
boolean
|
<optional> |
false | true = case sensitive. false = case insensitive. Default is false |
space |
boolean
|
<optional> |
false | true = space is count. false = space is not count as character. Default is false |
unique |
boolean
|
<optional> |
false | true = return only unique sequence. false = return all sequence. Default is false |
anagram words/sequences
Array
Examples
findPattern("car", "race car care") // [ 'rac', 'car', 'arc', 'rca', 'car' ]
findPattern("car", "race car care", {space: true, unique: true}) // [ 'rac', 'car' ]
# isPalindrome(word, optionsopt) → {boolean}
Check if word is palindrome
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
word |
string
|
The word to check | ||
options |
Object
|
<optional> |
Options for customization | |
caseSensitive |
boolean
|
<optional> |
false | true = case sensitive. false = case insensitive. Default is false |
space |
boolean
|
<optional> |
false | true = space is count. false = space is not count as character. Default is false |
is the word palindrome
boolean
Examples
isPalindrome("Race car") // true
isPalindrome("Racecar", {caseSensitive: true}) // false
# removeSpaces(text) → {string}
Return new text without spaces
Parameters:
Name | Type | Description |
---|---|---|
text |
string
|
The text where spaces will be removed |
new text without spaces
string
Example
removeSpaces("race car") // 'racecar'
Type Definitions
object
# Hash
Hash
Properties:
Name | Type | Description |
---|---|---|
{...} |
number
|
key is a character, the value is the count of the character |
object
# Options
Options
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
caseSensitive |
boolean
|
<optional> |
if true, text is case sensitive |
space |
boolean
|
<optional> |
if true, spaces in text are counted as a character |
unique |
boolean
|
<optional> |
if true, returned array result will be unique |