Skip to content

Instantly share code, notes, and snippets.

@dcabines
Created February 17, 2016 18:44
Show Gist options
  • Select an option

  • Save dcabines/d7654fb72a454410eb0a to your computer and use it in GitHub Desktop.

Select an option

Save dcabines/d7654fb72a454410eb0a to your computer and use it in GitHub Desktop.
This is the same as the last one, just done a little differently.
String.prototype.toSmallCaps = (function () {
var letters = "abcdefghijklmnopqrstuvwxyz";
var caps = "ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ";
function translate(character) {
var index = letters.indexOf(character);
return index !== -1 ? caps.charAt(index) : character;
}
function mapReduce(value, transform) {
var newValue = '';
for (i = 0; i < value.length; i++) {
newValue += transform(value[i]);
}
return newValue;
}
return function toSmallCaps() {
return mapReduce(this, translate);
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment