Platinum Partner

Soundex //JavaScript Function



[UPDATED CODE AND HELP CAN BE FOUND HERE]


This function returns the phonetic code of a word.

example


alert("Jonas\nJones\nMatrix\nMaytrix".replace(/\w+/g, function(s){
	return s + " = " + s.soundex();
}));





//+ Jonas Raoni Soares Silva
//@ 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)
		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");
};
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}