skendrick
09/30/2019, 3:39 PMstr1 = "ABC"
str2 = "ABB"
diff = 1
// JS
str1.reduce((accumulator, currLetter, index) => {
if (currLetter !== str2[index]) return accumulator + 1
}, 0)
Is this a kotlin-y way to approach the problem or am I being a dingus?Shawn
09/30/2019, 3:41 PMfoldIndexed {}
!skendrick
09/30/2019, 3:43 PMPavlo Liapota
09/30/2019, 3:45 PMval str1 = "ABCDF"
val str2 = "ABBEF"
val diffs = str1.zip(str2)
.count { (ch1, ch2) -> ch1 != ch2}
Shawn
09/30/2019, 3:48 PMstr1.foldIndexed(initial = 0) { index, acc, char ->
if (char != str2[index]) acc + 1 else acc
}
skendrick
09/30/2019, 3:55 PM