Created
January 6, 2021 15:51
-
-
Save digimon1740/99cc0e38c1f941c8a88268de1d155885 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main () { | |
val differ = differString("abc", "abd") { index, a, b -> | |
a != b | |
} | |
println("differ : $differ") | |
} | |
fun differString(a: String, b: String, predicate: (index: Int, a: Char, b: Char) -> Boolean): Boolean { | |
val org = a.toCharArray() | |
val diff = b.toCharArray() | |
if (org.size != diff.size) { | |
return false | |
} | |
var idx = 0 | |
var different = false | |
for (i in org) { | |
if (predicate(idx, i, diff[idx])) { | |
different = true | |
break | |
} | |
idx++ | |
} | |
return different | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment