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; +}