Created
February 17, 2016 18:44
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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