From ab063209f20b0ffac3047c843f55ba21cc23c889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Andrea?= Date: Sat, 1 Aug 2020 14:37:31 -0500 Subject: [PATCH 1/2] Hamming Distance Algorithm --- src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 243d154..716b040 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,12 @@ */ const hammingDistance = (a, b) => { - - } + if(a.length != b.length) + throw new TypeError('Strings of different lengths'); + const arrayA = a.split(''); + const arrayB = b.split(''); + return result = arrayA.reduce((acc, current, index) => ( + current !== arrayB[index] ? ++acc : acc),0) +} module.exports = hammingDistance; \ No newline at end of file From 8f4ba128b73927d1cf5356d17243eb48c51ffb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Andrea?= Date: Sat, 1 Aug 2020 14:38:45 -0500 Subject: [PATCH 2/2] Hamming Distance Algorithm --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 716b040..dd8c59e 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const hammingDistance = (a, b) => { throw new TypeError('Strings of different lengths'); const arrayA = a.split(''); const arrayB = b.split(''); - return result = arrayA.reduce((acc, current, index) => ( + return arrayA.reduce((acc, current, index) => ( current !== arrayB[index] ? ++acc : acc),0) }