From 2101620ab575f905cdb39059471debcbe1d863e1 Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Tue, 9 Oct 2018 15:31:54 +0100 Subject: [PATCH 1/7] initial introduction --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 4c3a580..e8dad2c 100644 --- a/README.md +++ b/README.md @@ -1 +1,28 @@ # Maths but with Javascript +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 From 8a3dd6c028847bf27e80c4e2b53975131916ed34 Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Wed, 10 Oct 2018 20:01:43 +0100 Subject: [PATCH 2/7] feat: union --- .babelrc | 5 +++++ package.json | 20 ++++++++++++++++++++ src/index.js | 1 + src/union.js | 1 + test/union.test.js | 5 +++++ 5 files changed, 32 insertions(+) create mode 100644 .babelrc create mode 100644 package.json create mode 100644 src/index.js create mode 100644 src/union.js create mode 100644 test/union.test.js 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/package.json b/package.json new file mode 100644 index 0000000..4b12895 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "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" + }, + "devDependencies": { + "babel-core": "^6.26.3", + "babel-jest": "^23.6.0", + "jest": "^23.6.0", + "regenerator-runtime": "^0.12.1" + }, + "dependencies": { + "babel-preset-env": "^1.7.0" + } +} 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 From 2c676a3a4d75c8711cd11528a1b46a3218dde24a Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Wed, 10 Oct 2018 20:02:01 +0100 Subject: [PATCH 3/7] docs: update top line --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8dad2c..5d8d972 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Maths but with Javascript -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. +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}` From d714184b5f4de770fed13aa70538cd502a086f9d Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Wed, 10 Oct 2018 20:02:54 +0100 Subject: [PATCH 4/7] chore: gitingore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore 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 From 3fa004b25f0de67500ff6ba7c2fbeda1a032fe30 Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Wed, 10 Oct 2018 20:03:13 +0100 Subject: [PATCH 5/7] test: add travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..587bd3e --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: node_js From 45cbd3ac75466aa6131398be0fbe32667611cc02 Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Wed, 10 Oct 2018 20:07:03 +0100 Subject: [PATCH 6/7] add engines --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4b12895..d9b365d 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,16 @@ "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" + "regenerator-runtime": "^0.12.1", + "babel-preset-env": "^1.7.0" }, "dependencies": { - "babel-preset-env": "^1.7.0" } } From badf071277f1caaa968d2566fc93aa8b0eafa299 Mon Sep 17 00:00:00 2001 From: Samuel Stenton Date: Wed, 10 Oct 2018 20:09:58 +0100 Subject: [PATCH 7/7] update node version for travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 587bd3e..efb0983 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,3 @@ language: node_js +node_js: + - "8"