41 lines
879 B
Text
41 lines
879 B
Text
code: #[
|
|
"aeiouy": 'W'
|
|
"bfpv": '1'
|
|
"cgjkqsxz": '2'
|
|
"dt": '3'
|
|
"l": '4'
|
|
"mn": '5'
|
|
"r": '6'
|
|
]
|
|
|
|
getCode: function [ch][
|
|
loop keys code 'k [
|
|
if contains? k lower to :string ch -> return code\[k]
|
|
]
|
|
return ' '
|
|
]
|
|
|
|
soundex: function [str][
|
|
result: to :string first str
|
|
|
|
prev: getCode first str
|
|
loop.with:'i str 'c [
|
|
curr: getCode c
|
|
if curr <> ' ' [
|
|
if and? curr <> 'W'
|
|
curr <> prev -> 'result ++ curr
|
|
prev: curr
|
|
]
|
|
]
|
|
|
|
switch 4 < size result -> result: slice result 0 3
|
|
[
|
|
do.times: 4-size result ->
|
|
'result ++ '0'
|
|
]
|
|
return result
|
|
]
|
|
|
|
loop ["Robert", "Rupert", "Rubin", "Ashcraft", "Ashcroft", "Tymczak",
|
|
"Pfister", "Honeyman", "Moses", "O'Mally", "O'Hara", "D day"] 'name ->
|
|
print [pad name 10 "->" soundex name]
|