Coder Social home page Coder Social logo

nodef / extra-set Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 536 KB

A pack of functions for working with Sets.

Home Page: https://www.npmjs.com/package/extra-set

License: MIT License

TypeScript 86.35% JavaScript 13.65%
extra set difference add chunk compare concat count cartesian-product count-as

extra-set's Introduction

A pack of functions for working with Sets.
๐Ÿ“ฆ Node.js, ๐ŸŒ Web, ๐Ÿ“œ Files, ๐Ÿ“ฐ Docs, ๐Ÿ“˜ Wiki.

A Set is a collection of unique values. This package includes common set functions related to querying about sets, generating them, comparing one with another, finding their size, adding and removing elements, obtaining its properties, getting a part of it, getting a subset elements in it, finding an element in it, performing functional operations, manipulating it in various ways, combining together sets or its elements, of performing set operations upon it.

All functions except from*() take set as 1st parameter. Methods like concat() are pure and do not modify the set itself, while methods like concat$() do modify (update) the set itself.

This package is available in Node.js and Web formats. The web format is exposed as extra_set standalone variable and can be loaded from jsDelivr CDN.

Stability: Experimental.


const set = require('extra-set');
// import * as set from "extra-set";
// import * as set from "https://unpkg.com/extra-set/index.mjs"; (Deno)

var x = new Set([1, 2, 3, 4, 5]);
var y = new Set([2, 4]);
set.difference(x, y);
// โ†’ Set(3) { 1, 3, 5 }

var x = new Set([1, 2, 3]);
var y = new Set([3, 4]);
set.isDisjoint(x, y);
// โ†’ false

var x = new Set([1, 2, 3, 4]);
var y = new Set([3, 4, 5, 6]);
set.symmetricDifference(x, y);
// โ†’ Set(4) { 1, 2, 5, 6 }

var x = new Set([1, 2, 3]);
[...set.subsets(x)];
// โ†’ [
// โ†’   Set(0) {},
// โ†’   Set(1) { 1 },
// โ†’   Set(1) { 2 },
// โ†’   Set(2) { 1, 2 },
// โ†’   Set(1) { 3 },
// โ†’   Set(2) { 1, 3 },
// โ†’   Set(2) { 2, 3 },
// โ†’   Set(3) { 1, 2, 3 }
// โ†’ ]


Index

Property Description
is Check if value is a set.
values List all values.
entries List all value-value pairs.
from Convert an iterable to set.
from$ Convert an iterable to set.
compare Compare two sets.
isEqual Check if two sets are equal.
size Find the size of a set.
isEmpty Check if a set is empty.
add Add a value to set.
add$ Add a value to set.
remove Delete a value from set.
remove$ Delete a value from set.
count Count values which satisfy a test.
countAs Count occurrences of values.
min Find smallest value.
max Find largest value.
range Find smallest and largest entries.
head Get first value from set (default order).
tail Get a set without its first value (default order).
take Keep first n values only (default order).
take$ Keep first n values only (default order).
drop Remove first n values (default order).
drop$ Remove first n values (default order).
subsets List all possible subsets.
randomValue Pick an arbitrary value.
randomEntry Pick an arbitrary entry.
randomSubset Pick an arbitrary subset.
hasSubset Checks if set has a subset.
has Check if set has a value.
find Find first value passing a test (default order).
findAll Find all values passing a test.
forEach Call a function for each value.
some Check if any value satisfies a test.
every Check if all values satisfy a test.
map Transform values of a set.
map$ Transform values of a set.
reduce Reduce values of set to a single value.
filter Keep values which pass a test.
filter$ Keep values which pass a test.
reject Discard values which pass a test.
reject$ Discard values which pass a test.
flat Flatten nested set to given depth.
flatMap Flatten nested set, based on map function.
partition Segregate values by test result.
partitionAs Segregates values by similarity.
chunk Break set into chunks of given size.
concat Append values from sets.
concat$ Append values from sets.
join Join values together into a string.
isDisjoint Check if sets have no value in common.
union Obtain values present in any set.
union$ Obtain values present in any set.
intersection Obtain values present in both sets.
intersection$ Obtain values present in both sets.
difference Obtain values not present in another set.
difference$ Obtain values not present in another set.
symmetricDifference Obtain values not present in both sets.
symmetricDifference$ Obtain values not present in both sets.
cartesianProduct List cartesian product of sets.


ORG DOI Coverage Status Test Coverage Maintainability

extra-set's People

Contributors

wolfram77 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

tolabenjo-va

extra-set's Issues

`isEqual` for sets of sets?

In set theoretic terms I believe these two sets should be equal:

{{1,2}} and {{2, 1}}

Where {{1,2}} is a set of a single set of two integers. In a Node module file this would be:

const set = await import('extra-set');

var x = new Set([1, 2]);
var xs = new Set([x]);
var y = new Set([2, 1]);
var ys = new Set([y]);

console.log(set.isEqual(xs, ys));
// returns false

Is the isEqual function effectively a shallow comparison?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.