From 2f58dbb9aec135342c4ee748b5e60aa7847cacdd Mon Sep 17 00:00:00 2001 From: Mary Date: Tue, 11 Dec 2018 15:32:32 -0500 Subject: [PATCH] Update oneAway.js --- chapter01/1.5 - OneAway/oneAway.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/chapter01/1.5 - OneAway/oneAway.js b/chapter01/1.5 - OneAway/oneAway.js index 1e66a89..e2e80bd 100644 --- a/chapter01/1.5 - OneAway/oneAway.js +++ b/chapter01/1.5 - OneAway/oneAway.js @@ -61,4 +61,19 @@ var oneAway = function(string1, string2) { console.log(oneAway('pale', 'ple'), true); console.log(oneAway('pales', 'pale'), true); console.log(oneAway('pale', 'bale'), true); -console.log(oneAway('pale', 'bake'), false); \ No newline at end of file +console.log(oneAway('pale', 'bake'), false); + +//Another solution +function oneAway(str1, str2) { + var counter = 0; + for (var i = 0; i < str1.length; i++) { + if (!str2.includes(str1.charAt(i))) { + counter++; + } + }; + + if (counter > 1) { + return false; + } + return true; +}