Class: Checker

anagram. Checker

The checker is a utility to easily compare a source string and a proposed anagram.

It comes with utilities to determine what characters have been used or not, and which were not part of the original source.

Non-letter characters are ignored, diacritics and ligatures can be removed to keep their latin equivalent, or be considered as is.

This checker is not case-sensitive.

Constructor

new Checker(stripDiacritics, original, proposition)

Creates a new instance.
Parameters:
Name Type Description
stripDiacritics boolean true if diacritics should be removed, false otherwise (default = true).
original string The original string.
proposition string An anagram proposition.
Source:

Methods

getDiff() → {Object}

Returns an object containing the characters available for an anagram from the original string after having removed those used in the proposition.

The result has a property for each character, and the corresponding value is the cardinality of this character in the original string. If more instances of a character were used than available in the original string, they will have a negative cardinality in the diff object.

If the diacritics stripping is active, this object will contain only latin letters.

Source:
Returns:
An object containing the characters as properties and their cardinality as values
Type
Object

getOriginal() → {string}

Returns the original string this checker checks anagrams for.
Source:
Returns:
The original string
Type
string

getOriginalChars() → {Object}

Returns an object containing the characters available for an anagram from the original string.

The result has a property for each character, and the corresponding value is the cardinality of this character in the original string.

If the diacritics stripping is active, this object will contain only latin letters.

Source:
Returns:
An object containing the characters as properties and their cardinality as values
Type
Object

getProposition() → {string}

Returns the current proposition for an anagram.
Source:
Returns:
The proposition
Type
string

isAnagram() → {boolean}

Checks whether the proposition is an anagram of the original string.

If the diacritics stripping is inactive, the anagram must use the same diacritics as the original string.

Source:
Returns:
true if the current proposition is an anagram of the original string, false otherwise
Type
boolean

propose(proposition) → {Checker}

Registers a string as a proposition for an anagram of the original string.

The diff is immediately recomputed.

Parameters:
Name Type Description
proposition string The anagram proposition.
Source:
Returns:
The current instance
Type
Checker

updateOriginal(original) → {Checker}

Changes the original string and updates the state accordingly.

This means the available characters and diff are recomputed immediately.

Parameters:
Name Type Description
original string The original string.
Source:
Returns:
The current instance
Type
Checker

updateStripDiacritics(stripDiacritics) → {Checker}

Changes the diacritics behavior and updates the state accordingly.

This means the available characters and diff are recomputed immediately.

Parameters:
Name Type Description
stripDiacritics boolean true if diacritics should be removed, false otherwise (default = true).
Source:
Returns:
The current instance
Type
Checker