Created
August 4, 2015 00:45
-
-
Save luisangelma/8738983679da189cacd9 to your computer and use it in GitHub Desktop.
Anti caps
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
| var isCaps = function(letter) { | |
| return letter === letter.toUpperCase(); | |
| }; | |
| var antiCaps = function(str) { | |
| if (!str && str.length <= 0) { | |
| console.log('Please use a string'); | |
| } | |
| var newStr = ''; | |
| for (var i = 0; i < str.length; i++) { | |
| var letter = str[i]; | |
| if (isCaps(letter)) { | |
| letter = letter.toLowerCase(); | |
| } else { | |
| letter = letter.toUpperCase(); | |
| } | |
| newStr += letter; | |
| } | |
| return newStr; | |
| }; | |
| console.log(antiCaps('WordTocapiTALIZe')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment