Soundex: Difference between revisions

1,201 bytes added ,  3 years ago
Added Arturo implementation
(Added Arturo implementation)
Line 330:
310 LET FNSoundex$ = s$(1:4)
320 END FUNCTION</lang>
 
=={{header|Arturo}}==
 
<lang rebol>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: new 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
]
]
 
if? 4 < size result ->
result: new slice result 0 3
else [
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]</lang>
 
{{out}}
 
<pre> Robert -> R163
Rupert -> R163
Rubin -> R150
Ashcraft -> A261
Ashcroft -> A261
Tymczak -> T522
Pfister -> P236
Honeyman -> H555
Moses -> M220
O'Mally -> O540
O'Hara -> O600
D day -> D000</pre>
 
 
=={{header|AutoHotkey}}==
1,532

edits