Skip to content

Commit

Permalink
adds documentation for methods, updates the comparison method
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank M. Taylor committed Sep 25, 2024
1 parent e4d3035 commit a905458
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Note: This doesn't use sentence punctuation as a boundary. Should it?
`Map<string, number>`

#### `getIntersection(iterable1, iterable2)`
returns an array of items that occur in both iterables
Returns an array of items that occur in both iterables

**Parameters**
| name | type | Description |
Expand All @@ -216,7 +216,7 @@ Returns an array that is the union of two iterables
A union of the items that occur in both iterables.

#### `getDisjunctiveUnion(iterable1, iterable2)`
returns an array of arrays of the unique items in either iterable
Returns an array of arrays of the unique items in either iterable. Also known as the symmetric difference

**Parameters**
| name | type | Description |
Expand All @@ -228,8 +228,21 @@ returns an array of arrays of the unique items in either iterable
`Array<Array<any>`
An array of arrays of the unique items. The first item is the first parameter, 2nd item second param

#### `getDifference`
Returns an array of items that are unique only to the first parameter.

**Parameters**
| name | type | Description |
| --- |--- | --- |
| iterable1 | `Map|Array` | |
| iterable2 | `Map|Array` | |

**Returns**
`Array<Array<any>`
An array of items unique only to the first parameter

#### `getComparison(iterable1, iterable2)`
returns a map containing various comparisons between two iterables
Returns a map containing various comparisons between two iterables

**Parameters**
| name | type | Description |
Expand All @@ -239,7 +252,7 @@ returns a map containing various comparisons between two iterables

**Returns**
`Map<string, <array>>`
A map containing various comparisons between two iterables. Those comparisons will be some kind of array (See intersection or disjunctiveUnion)
A map containing various comparisons between two iterables. Those comparisons will be arrays of intersection, disjunctiveUnion, difference, and union.

#### `getWordPlacementForNGram(ngram, wordsArray)`
determines the placement of a single ngram in an array of words
Expand Down
8 changes: 5 additions & 3 deletions src/functions.comparisons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function getDisjunctiveUnion(
* @description returns the items unique only to the first iterable
* @param {Map|Array} iterable1 A map or array
* @param {Map|Array} iterable2 A map or array
* @returns {Array<string>} An array of arrays of the unique items. The first item is the first parameter, 2nd item second param
* @returns {Array<string>} An array of items that are unique to the first iterable
*/
function getDifference(
iterable1: Map<string, string> | Array<string>,
Expand All @@ -115,7 +115,7 @@ function getDifference(
}

/** The type of way that two NGramSequences can be evaluated */
type SequenceComparisonType = 'intersection' | 'disjunctiveUnion';
type SequenceComparisonType = 'intersection' | 'disjunctiveUnion | union | difference-AB | difference-BA';

/** A map containing various comparisons between two iterables */
type SequenceComparison = Map<SequenceComparisonType, Intersection | DisjunctiveUnion>;
Expand All @@ -133,7 +133,9 @@ function getComparison(
const comparison = new Map();
comparison.set('intersection', getIntersection(iterable1, iterable2));
comparison.set('disjunctiveUnion', getDisjunctiveUnion(iterable1, iterable2));

comparison.set('difference-AB', getDifference(iterable1, iterable2));
comparison.set('difference-BA', getDifference(iterable2, iterable1));
comparison.set('union', getDifference(iterable2, iterable1));
return comparison;
}

Expand Down

0 comments on commit a905458

Please sign in to comment.