From 60588bb9419fc6c94a0783b9dfa2cb76f4a420b3 Mon Sep 17 00:00:00 2001 From: Paul Montoya <52388061+PaulMoro@users.noreply.github.com> Date: Fri, 24 Jul 2020 23:05:02 -0500 Subject: [PATCH] CHALLENGE SOLVE --- src/index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 243d154..55a20f5 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,23 @@ */ const hammingDistance = (a, b) => { - + + let hammingDistance = 0 + + if (a.length == b.length) { + + for (i = 0; i < a.length; i++) { + + if(a.charAt(i) !== b.charAt(i)) { + hammingDistance++ + } + } + } else { + throw new Error('Sorry, I can not to compare it') + } + + return hammingDistance; +} } - module.exports = hammingDistance; \ No newline at end of file + module.exports = hammingDistance;