We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a77c29b commit 4fb27eeCopy full SHA for 4fb27ee
functions/strings/soundex.js
@@ -15,25 +15,22 @@ function soundex (str) {
15
// * example 3: soundex('Euler');
16
// * returns 3: 'E460'
17
18
- var upStr = (str+'').toUpperCase();
19
- var sdx = [upStr.charAt(0),0,0,0],
20
- m = {BFPV: 1, CGJKQSXZ: 2, DT: 3, L: 4, MN: 5, R: 6 },
21
- k = ['BFPV', 'CGJKQSXZ', 'DT', 'L', 'MN', 'R'],
22
- i = 1, j = 0, s = 0, key, code,
23
- l = upStr.length;
+ str = (str + '').toUpperCase();
+ var sdx = [str.charAt(0), 0, 0 , 0],
+ k = ['BFPV', 'CGJKQSXZ', 'DT', 'L', 'MN', 'R'], kl = k.length,
+ i = 1, j = 0, s = 0, c, p;
24
25
- for (; i < l; i++){
26
- j = k.length;
27
- while (s !== 3 && j--){
28
- key = k[j];
29
- if (key.indexOf(upStr.charAt(i)) !== -1) {
30
- code = m[key];
31
- if (code !== sdx[s]){
32
- sdx[++s] = code;
+ while ((c = str.charAt(i++)) && s < 3 ){
+ j = 0;
+ while (p = k[j++]){
+ if (p.indexOf(c) !== -1) {
+ if (j !== sdx[s]){
+ sdx[++s] = j;
33
}
+ break;
34
35
36
37
-
38
return sdx.join('');
39
+
0 commit comments