From 42e01cee62409c2fb963e5efdca65bcb257addf4 Mon Sep 17 00:00:00 2001 From: Hector Remedios Date: Thu, 23 Jul 2020 01:38:41 -0500 Subject: [PATCH] Function to calculate the difference between two chains --- src/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/index.js b/src/index.js index 243d154..068873d 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,14 @@ const hammingDistance = (a, b) => { + if (a.length === b.length) { + const aArray = a.split(''); + const bArray = b.split(''); + return bArray.filter((letter, index) => aArray[index] !== letter).length + } else { + throw new Error("You must enter strings with the same length"); + } + } module.exports = hammingDistance; \ No newline at end of file