Here you can find the source of soundex(p)
//@ http://jsfromhell.com/string/soundex [v1.0] String.prototype.soundex = function(p){ //v1.0 var i, j, r, p = isNaN(p) ? 4 : p > 10 ? 10 : p < 4 ? 4 : p, m = {BFPV: 1, CGJKQSXZ: 2, DT: 3, L: 4, MN: 5, R: 6}, r = (s = this.toUpperCase().replace(/[^A-Z]/g, "").split("")).splice(0, 1); for(i in s)/*ww w. j a va2s . c om*/ for(j in m) if(j.indexOf(s[i]) + 1 && r[r.length-1] != m[j] && r.push(m[j])) break; return r.length > p && (r.length = p), r.join("") + (new Array(p - r.length + 1)).join("0"); };
String.prototype.soundex = function( ){ var i, j, r; var keyLength = 4; var map = { 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 }; var r = (s = this.toUpperCase().replace(/[^A-Z]/g, "").split("")).splice(0, 1); var key = { items : [], _check: function(e) { var m = map[e]; ...
String.prototype.soundex = function() return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase() .replace(/\w/g, function($0) return String.prototype.soundex.table[$0]; }) .replace(/(.)\1+/g, '$1') .slice(0, 3) ...
String.prototype.soundex = function(p){ var i, j, l, r, p = isNaN(p) ? 4 : p > 10 ? 10 : p < 4 ? 4 : p, m = {BFPV: 1, CGJKQSXZ: 2, DT: 3, L: 4, MN: 5, R: 6}, r = (s = this.toUpperCase().replace(/[^A-Z]/g, "").split("")).splice(0, 1); for(i = -1, l = s.length; ++i < l;) for(j in m) if(j.indexOf(s[i]) + 1 && r[r.length-1] != m[j] && r.push(m[j])) break; return r.length > p && (r.length = p), r.join("") + (new Array(p - r.length + 1)).join("0"); ...
String.prototype.soundex.init = function(table) String.prototype.soundex.table = {}; table = table || { 'bfpv': '1', 'cgjkqsxz': '2', 'dt': '3', 'l': '4', 'mn': '5', ...
var US_ENGLISH_MAPPING = "01360240043788015936020505".split(""); var lookup = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""); String.prototype.soundexRefined = function(){ if (this == null){ return null; var str = this.toUpperCase().replace(/[^A-Z]/g, ""); if (this.length == 0) { return str; ...