diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..6a9be79 --- /dev/null +++ b/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "env" + ] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ca9b82 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/ +node_modules/ +yarn.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..efb0983 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "8" diff --git a/README.md b/README.md index 4c3a580..5d8d972 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d9b365d --- /dev/null +++ b/package.json @@ -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 ", + "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": { + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..831151d --- /dev/null +++ b/src/index.js @@ -0,0 +1 @@ +export { union } from './union'; diff --git a/src/union.js b/src/union.js new file mode 100644 index 0000000..7e9af78 --- /dev/null +++ b/src/union.js @@ -0,0 +1 @@ +export const union = (a,b) => Array.from(new Set(a.concat(b))); diff --git a/test/union.test.js b/test/union.test.js new file mode 100644 index 0000000..db2e827 --- /dev/null +++ b/test/union.test.js @@ -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])); +}); \ No newline at end of file