-
-
Save manjeettahkur/945940a0359c08f3d8bf66847248ef83 to your computer and use it in GitHub Desktop.
Write a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased. The indexing just explained is zero based, so the zero-ith index is even, therefore that character should be upper cased. The passe…
This file contains 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
function toWeirdCase(string){ | |
let newString = string.split(' '); | |
for(let i = 0; i < newString.length; i++){ | |
newString[i] = newString[i].weird(); | |
} | |
return newString.join(' '); | |
} | |
String.prototype.weird = function( ){ | |
var newString = ''; | |
for(let i = 0; i< this.length ; i++){ | |
newString += (i % 2 === 0)? this[i].toUpperCase():this[i].toLowerCase(); | |
} | |
return newString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment