-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathone-away-strings.js
35 lines (35 loc) · 1.29 KB
/
one-away-strings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Working with one away strings
/***
* Write a function that takes two string s and returns true
* if they are one away from each other.
*
*
*/
var s1 = "abcde";
var s2 = "abfde";
function isOneAwayFromEachOther(stringOne, stringTwo) {
if (stringOne.length != stringTwo.length) {
return false;
}
// log the two strings to the console.
// console.log('stringOne: ',stringOne);
// console.log('stringTwo: ',stringTwo);
var indexNumber = -1;
var equalChars = 0;
var unEqualChars = 0;
for (var _i = 0, stringOne_1 = stringOne; _i < stringOne_1.length; _i++) {
var theLetter = stringOne_1[_i];
indexNumber += 1;
// console.log('stringOne['+ indexNumber + ']', theLetter);
// console.log('stringTwo['+ indexNumber + ']', theLetter);
if (stringOne[indexNumber] == stringTwo[indexNumber]) {
console.log('both characters are equal!!');
}
else if (stringOne[indexNumber] != stringTwo[indexNumber]) {
console.log('@ Position: ' + indexNumber + ' The Characters: ' + stringOne[indexNumber] + ' & ' + stringTwo[indexNumber]);
console.log('Hmm... these two are not equal the strings do not match!!');
unEqualChars += 1;
}
}
}
console.log(isOneAwayFromEachOther(s1, s2));