Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update type documentation #15

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/combinations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* </lisence>
* </license>
*
* Implements functions to calculate combinations of elements in JS Arrays.
*
* Functions:
* kCombinations(set, k) -- Return all k-sized combinations in a set
* combinations(set) -- Return all combinations of the set
* kCombinations(set, k) -- Return all non-empty k-sized combinations in a set
* combinations(set) -- Return all non-empty combinations of the set
*/

/**
Expand All @@ -50,11 +50,13 @@
* ```
* @param set Array of objects of any type. They are treated as unique.
* @param k Size of combinations to search for.
* @returns Array of found combinations, size of a combination is k.
* @returns Array of found non-empty combinations, size of a combination is k.
*/
export function kCombinations<T>(set: T[], k: number): T[][] {
// There is no way to take e.g. sets of 5 elements from
// a set of 4.
// All sets with 0 elements are empty.
// A set with negative amount of elements makes no sense.
if (k > set.length || k <= 0) {
return [];
}
Expand Down Expand Up @@ -143,6 +145,8 @@ export function* iterKCombinations<T>(
): Generator<T[], number, undefined> {
// There is no way to take e.g. sets of 5 elements from
// a set of 4.
// All sets with 0 elements are empty.
// A set with negative amount of elements makes no sense.
if (k > set.length || k <= 0) {
return 0;
}
Expand Down
Loading
Loading