Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created October 6, 2011 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriskowal/1268953 to your computer and use it in GitHub Desktop.
Save kriskowal/1268953 to your computer and use it in GitHub Desktop.
var GRAWLIX = "@#$%&*";
String.prototype.grawlix = function () {
return this.split(" ").map(function (word) {
var dictionary = {};
var previous;
return Array.prototype.map.call(word, function (char) {
if (!/\w/.test(char))
return char;
var code = char.charCodeAt();
if (!dictionary[code]) {
dictionary[code] = GRAWLIX[code % GRAWLIX.length];
if (previous == dictionary[code])
dictionary[code] = GRAWLIX[(code + 1) % GRAWLIX.length];
previous = dictionary[code];
}
return dictionary[code];
}).join("");
}).join(" ");
};
console.log("fuck".grawlix());
console.log("ass".grawlix());
console.log("poo darn!!".grawlix());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment