From baef1fccd819d8b002d0faa06d6fc478a20cb096 Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 15:31:33 +0000 Subject: [PATCH 01/11] Create vectorDistance.md --- vectorDistance.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 vectorDistance.md diff --git a/vectorDistance.md b/vectorDistance.md new file mode 100644 index 000000000..425c2a2b0 --- /dev/null +++ b/vectorDistance.md @@ -0,0 +1,17 @@ +### VectorDistance + +Explain briefly what the snippet does. + +Explain briefly how the snippet works. + +```js +const vectorDistance = (...coords) => { + let length = Math.trunc(coords.length/2); + let sum = coords.slice(0,length).reduce((accumulator,currentValue,currentIndex) => accumulator + (Math.pow(currentValue-coords[length+currentIndex],2)),0); + return Math.sqrt(sum); +} +``` + +```js +vectorDistance(10,0,5,20,0,10) //11.180339887498949 +``` From 783bca0f5cc93a73fdfb55d0e71c9cef6c54e01a Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 15:41:04 +0000 Subject: [PATCH 02/11] Update vectorDistance.md --- vectorDistance.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vectorDistance.md b/vectorDistance.md index 425c2a2b0..275ec6596 100644 --- a/vectorDistance.md +++ b/vectorDistance.md @@ -1,8 +1,8 @@ ### VectorDistance -Explain briefly what the snippet does. +Returns the distance between two points. -Explain briefly how the snippet works. +Splits the arguments array into two points. Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. ```js const vectorDistance = (...coords) => { From dd05ef9ba8a91790f190a48419cd9a9df95ddda5 Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 15:42:20 +0000 Subject: [PATCH 03/11] Update vectorDistance.md --- vectorDistance.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vectorDistance.md b/vectorDistance.md index 275ec6596..b24efcc32 100644 --- a/vectorDistance.md +++ b/vectorDistance.md @@ -2,12 +2,12 @@ Returns the distance between two points. -Splits the arguments array into two points. Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. +Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. ```js const vectorDistance = (...coords) => { - let length = Math.trunc(coords.length/2); - let sum = coords.slice(0,length).reduce((accumulator,currentValue,currentIndex) => accumulator + (Math.pow(currentValue-coords[length+currentIndex],2)),0); + let pointLength = Math.trunc(coords.length/2); + let sum = coords.slice(0,pointLength).reduce((accumulator,currentValue,currentIndex) => accumulator + (Math.pow(currentValue-coords[pointLength+currentIndex],2)),0); return Math.sqrt(sum); } ``` From 0a8812309aea2557b7d530d663cb581b51f289a1 Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 15:44:22 +0000 Subject: [PATCH 04/11] Update tag_database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index 785aa026e..7d248af61 100644 --- a/tag_database +++ b/tag_database @@ -332,6 +332,7 @@ URLJoin:string,utility,regexp,advanced UUIDGeneratorBrowser:browser,utility,random,intermediate UUIDGeneratorNode:node,utility,random,intermediate validateNumber:utility,math,intermediate +vectorDistance:math,beginner when:function,intermediate without:array,beginner words:string,regexp,intermediate From 4cd48fdd5e899d49e40a98b3489a3e5f6b73c601 Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 15:48:20 +0000 Subject: [PATCH 05/11] Create vectorDistance.test.js --- test/vectorDistance.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/vectorDistance.test.js diff --git a/test/vectorDistance.test.js b/test/vectorDistance.test.js new file mode 100644 index 000000000..2efa78bc0 --- /dev/null +++ b/test/vectorDistance.test.js @@ -0,0 +1,9 @@ +const expect = require('expect'); +const {vectorDistance} = require('./_30s.js'); + +test('vectorDistance is a Function', () => { + expect(vectorDistance).toBeInstanceOf(Function); +}); +test('Calculates the distance between two vectors', () => { + expect(distance(10,0,5,20,0,10)).toBeCloseTo(11.180339887498949, 5); +}); From 9978d6d08b344291eadca81dd78f91f6dd4bd08e Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 15:49:53 +0000 Subject: [PATCH 06/11] Update vectorDistance.md --- vectorDistance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vectorDistance.md b/vectorDistance.md index b24efcc32..90457925a 100644 --- a/vectorDistance.md +++ b/vectorDistance.md @@ -1,6 +1,6 @@ ### VectorDistance -Returns the distance between two points. +Returns the distance between two vectors. Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. From de8bf3b1d18347dff70bda012fc2a44065a6d1a7 Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 17:13:48 +0000 Subject: [PATCH 07/11] Create vectorDistance.md --- snippets/vectorDistance.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/vectorDistance.md diff --git a/snippets/vectorDistance.md b/snippets/vectorDistance.md new file mode 100644 index 000000000..90457925a --- /dev/null +++ b/snippets/vectorDistance.md @@ -0,0 +1,17 @@ +### VectorDistance + +Returns the distance between two vectors. + +Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. + +```js +const vectorDistance = (...coords) => { + let pointLength = Math.trunc(coords.length/2); + let sum = coords.slice(0,pointLength).reduce((accumulator,currentValue,currentIndex) => accumulator + (Math.pow(currentValue-coords[pointLength+currentIndex],2)),0); + return Math.sqrt(sum); +} +``` + +```js +vectorDistance(10,0,5,20,0,10) //11.180339887498949 +``` From b35ce12712329afdce2a2946a191ad676f9efaf5 Mon Sep 17 00:00:00 2001 From: Yusof Bandar Date: Sat, 23 Feb 2019 17:14:14 +0000 Subject: [PATCH 08/11] Delete vectorDistance.md --- vectorDistance.md | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 vectorDistance.md diff --git a/vectorDistance.md b/vectorDistance.md deleted file mode 100644 index 90457925a..000000000 --- a/vectorDistance.md +++ /dev/null @@ -1,17 +0,0 @@ -### VectorDistance - -Returns the distance between two vectors. - -Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. - -```js -const vectorDistance = (...coords) => { - let pointLength = Math.trunc(coords.length/2); - let sum = coords.slice(0,pointLength).reduce((accumulator,currentValue,currentIndex) => accumulator + (Math.pow(currentValue-coords[pointLength+currentIndex],2)),0); - return Math.sqrt(sum); -} -``` - -```js -vectorDistance(10,0,5,20,0,10) //11.180339887498949 -``` From a2708ebbacf1b1e040b6031f1c9ca150d8a48f66 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 25 Feb 2019 08:30:33 +0200 Subject: [PATCH 09/11] Update vectorDistance.md --- snippets/vectorDistance.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/snippets/vectorDistance.md b/snippets/vectorDistance.md index 90457925a..1665fe44b 100644 --- a/snippets/vectorDistance.md +++ b/snippets/vectorDistance.md @@ -1,17 +1,17 @@ -### VectorDistance +### vectorDistance Returns the distance between two vectors. -Use `Array.prototype.reduce()`,`Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. +Use `Array.prototype.reduce()`, `Math.pow()` and `Math.sqrt()` to calculate the Euclidean distance between two vectors. ```js const vectorDistance = (...coords) => { - let pointLength = Math.trunc(coords.length/2); - let sum = coords.slice(0,pointLength).reduce((accumulator,currentValue,currentIndex) => accumulator + (Math.pow(currentValue-coords[pointLength+currentIndex],2)),0); + let pointLength = Math.trunc(coords.length / 2); + let sum = coords.slice(0, pointLength).reduce((acc, val, i) => acc + (Math.pow(val - coords[pointLength + i], 2)), 0); return Math.sqrt(sum); -} +}; ``` ```js -vectorDistance(10,0,5,20,0,10) //11.180339887498949 +vectorDistance(10, 0, 5, 20, 0, 10); // 11.180339887498949 ``` From a9878bf18e8e2bbfbaaa3a735d3510a1b8586f98 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 25 Feb 2019 08:30:50 +0200 Subject: [PATCH 10/11] Update vectorDistance.md --- snippets/vectorDistance.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/vectorDistance.md b/snippets/vectorDistance.md index 1665fe44b..db3261dcb 100644 --- a/snippets/vectorDistance.md +++ b/snippets/vectorDistance.md @@ -6,9 +6,9 @@ Use `Array.prototype.reduce()`, `Math.pow()` and `Math.sqrt()` to calculate the ```js const vectorDistance = (...coords) => { - let pointLength = Math.trunc(coords.length / 2); - let sum = coords.slice(0, pointLength).reduce((acc, val, i) => acc + (Math.pow(val - coords[pointLength + i], 2)), 0); - return Math.sqrt(sum); + let pointLength = Math.trunc(coords.length / 2); + let sum = coords.slice(0, pointLength).reduce((acc, val, i) => acc + (Math.pow(val - coords[pointLength + i], 2)), 0); + return Math.sqrt(sum); }; ``` From 94a9e4e30a8804292aed6e15a443101057fe3505 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 25 Feb 2019 08:31:21 +0200 Subject: [PATCH 11/11] Update vectorDistance.test.js --- test/vectorDistance.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/vectorDistance.test.js b/test/vectorDistance.test.js index 2efa78bc0..746eb645e 100644 --- a/test/vectorDistance.test.js +++ b/test/vectorDistance.test.js @@ -1,9 +1,9 @@ const expect = require('expect'); -const {vectorDistance} = require('./_30s.js'); +const { vectorDistance } = require('./_30s.js'); test('vectorDistance is a Function', () => { expect(vectorDistance).toBeInstanceOf(Function); }); test('Calculates the distance between two vectors', () => { - expect(distance(10,0,5,20,0,10)).toBeCloseTo(11.180339887498949, 5); + expect(distance(10, 0, 5, 20, 0, 10)).toBeCloseTo(11.180339887498949, 5); });