Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Soundex/Groovy/soundex.groovy
Normal file
23
Task/Soundex/Groovy/soundex.groovy
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def soundex(s) {
|
||||
def code = ""
|
||||
def lookup = [
|
||||
B : 1, F : 1, P : 1, V : 1,
|
||||
C : 2, G : 2, J : 2, K : 2, Q : 2, S : 2, X : 2, Z : 2,
|
||||
D : 3, T : 3,
|
||||
L : 4,
|
||||
M : 5, N : 5,
|
||||
R : 6
|
||||
]
|
||||
s[1..-1].toUpperCase().inject(7) { lastCode, letter ->
|
||||
def letterCode = lookup[letter]
|
||||
if(letterCode && letterCode != lastCode) {
|
||||
code += letterCode
|
||||
}
|
||||
}
|
||||
return "${s[0]}${code}0000"[0..3]
|
||||
}
|
||||
|
||||
println(soundex("Soundex"))
|
||||
println(soundex("Sownteks"))
|
||||
println(soundex("Example"))
|
||||
println(soundex("Ekzampul"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue