Skip to content
Open
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
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"env"
]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/
node_modules/
yarn.lock
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "8"
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# Maths but with Javascript
This is a very experimental project, there is no point to this at all, except to have a little fun. If you would like to contribute please open a pull request.

### Sets
A set is a collection of distinct objects, considered as an object in its own right. For example, the number 1, 2 and 3 are but together they form an set of size three, written `{1,2,3}`

For the ease of development, a set in this repository is represented using array syntax. The following is how we will represent sets `A = {3, 8, 7, 16, 10, 15}` and `B = {1, 2, 8, 10, 15}`.
```javascript
const a = [3, 8, 7, 16, 10, 15];
const b = [1, 2, 8, 10, 15];
```

#### Equality
It is worth noting that the sets `A = {1,2,3}` and `B = {3, 1, 2}` are in fact equal as set theory does not care about order. In javascript however, comparing `[1,2,3]` and `[3, 1, 2]` would be false. Hell, even comparing `[1,2,3]` with `[1,2,3]` would produce false. Javascript `/shrug`

### Union
The Union of two sets produces a new set which are in a, b or both a and b.

```javascript
const a = [3, 8, 7, 16, 10, 15];
const b = [1, 2, 8, 10, 15];

const c = union(a, b);
// = [1, 2, 3, 7, 8, 10, 15, 16]
```
### Intersection

### Subset
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "maths-but-javascript",
"version": "1.0.0",
"main": "src/index.js",
"repository": "https://github.com/ITSociety/maths-but-javascript",
"author": "Samuel Stenton <sthstenton@gmail.com>",
"license": "MIT",
"scripts": {
"test": "jest"
},
"engines": {
"node": ">=8.9.0"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-jest": "^23.6.0",
"jest": "^23.6.0",
"regenerator-runtime": "^0.12.1",
"babel-preset-env": "^1.7.0"
},
"dependencies": {
}
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { union } from './union';
1 change: 1 addition & 0 deletions src/union.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const union = (a,b) => Array.from(new Set(a.concat(b)));
5 changes: 5 additions & 0 deletions test/union.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { union } = require('../src/index');

test('it should union two sets', () => {
expect(union([3, 8, 7, 16, 10, 15], [1, 2, 8, 10, 15])).toEqual(expect.arrayContaining([1, 2, 3, 7, 8, 10, 15, 16]));
});