Skip to content

Commit

Permalink
Merge pull request #3 from mary-tkachenko/mary-tkachenko-patch-3
Browse files Browse the repository at this point in the history
Update oneAway.js
  • Loading branch information
mary-tkachenko committed Dec 11, 2018
2 parents 01e77fe + ef11e70 commit 7abd4f9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion chapter01/1.5 - OneAway/oneAway.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ 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);
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;
}

0 comments on commit 7abd4f9

Please sign in to comment.