himpunan

tiny lib for array relation

Usage no npm install needed!

<script type="module">
  import himpunan from 'https://cdn.skypack.dev/himpunan';
</script>

README

:blossom: himpunan

npm_min npm version

javascript library untuk kalkulasi himpunan

Features

  • union of sets
  • intersection of sets
  • complement of sets

Install

$ npm install himpunan

or

$ yarn add himpunan

Usage

const { complement, union } = require("himpunan");

const s = [0, 1, 2, 3, 4, 5, 6, 7];
const k = [0, 1, 2, 3];
const l = [3, 4, 5];
  
// s - (k u l)
console.log(complement(s, union(k, l))); // [6,7]

API

union(arrA, arrB)

Returns an array union of sets

  const a = [1, 2, 3, 4, 5, 6, 7, 8];
  const b = [2, 4, 6, 8];
  const c = [2, 3, "a", "b", "c"];
  
  // (a u b)
  console.log(union(a, b)); // [1, 2, 3, 4, 5, 6, 7, 8]
  
  // (a u b) u c
  console.log(union(union(a, b), c)); // [1, 2, 3, 4, 5, 6, 7, 8, 'a', 'b', 'c']

intsec(arrA, arrB)

Returns an array intersection of sets

  const a = [1, 2, 3, 4, 5, 6, 7, 8];
  const b = [2, 4, 6, 8];
  const c = [2, 3, 7, 8];
  
  // (a n b) n c
  console.log(intsec(intsec(a, b), c)); // [2,8]

complement(arrSpace, arrEvent)

Returns an array complement of sets

  const s = [0, 1, 2, 3, 4, 5, 6, 7];
  const k = [0, 1, 2, 3];
  const l = [3, 4, 5];
  
  // s - (k u l)
  console.log(complement(s, union(k, l))); [6,7]