From 14b25cd006d30f9aaed656d36149274d76471558 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 e6597ea381c1f680e477c0a62f5bf6e0d5cd9cca 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 374d064e914ceb4b19b837121ee2507036a44e4c 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 6e6fe8c2a6e9336b438685787d6443706538caa6 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 9d26e0a93bb69bcb41aaab48df99380c80558c76 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 7ad2fa92acd21f8810252142da13bf351473715e 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 af9be08f363f17ce17378fa0f95b311706321a0c 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 3e7f17aefc435e0a692f1977cc4ef70c31750167 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 2c39c8a362e03f372ed0cc16da74eafa8b9f6ef5 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 9426b39365487be4667e790e66e1716f0055e4ab 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 0da7e8ce012b90d8a753bce06c609dc95d413c35 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); });