Created
February 12, 2015 20:31
-
-
Save kylebakerio/2cdfa648b8ebef6538ed to your computer and use it in GitHub Desktop.
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
var decryptC = function(message) { | |
console.log("Becky's Code") | |
var wordString = "", whatWord = "", results = "", result = "", messageArray = message.split(" "), arrayLength = messageArray.length; | |
for (var i = 0; i < arrayLength; i++) { //for each word (i) do the following | |
if(messageArray[i].length > [i]) { //if this word is longer than how many letters we need | |
result = messageArray[i].charAt(i); //add that letter of the word to result | |
results += result; //add result to the result string | |
} | |
else { | |
wordString = ""; | |
whatWord = i; //setting whatWord to the letter I need | |
while(wordString.length <= whatWord && i < messageArray.length) { //while my wordString doesn't have enough letters | |
wordString += messageArray[i]; | |
i++; | |
} | |
console.log("wordString is: " + wordString) | |
console.log("messageArray is: " + messageArray + " \n") | |
result = wordString.charAt(whatWord); | |
results += result; | |
i-- | |
} | |
} | |
return results; | |
}; | |
console.log("Answer is " + decryptC("Hello mY naMe is gEorge do you Like playing" )) //"HYMEL" | |
/*-------------------------------------*/ | |
var decryptK = function (message){ | |
console.log("\n \n Kyle's Code") | |
var messageArray = message.split(" "), results = "", result = "", c = 0; | |
for (i=0;i<messageArray.length;i++) { | |
if (messageArray[i].length > i){ | |
result = messageArray[i].charAt(i); | |
results += result; | |
} | |
else { | |
for (b=i+1;messageArray[i].length <= i;b++) { | |
if (b == messageArray.length){return results}; | |
messageArray[i] = messageArray[i] + messageArray[b]; | |
c++; | |
} | |
console.log("messageArray[i] is: " + messageArray[i]) | |
console.log("messageArray is: " + messageArray + "\n") | |
result = messageArray[i].charAt(i); | |
results += result; | |
i+=c; | |
c=0; | |
} | |
} | |
return results; | |
} | |
console.log("Answer is " + decryptK("Hello mY naMe is gEorge do you Like playing" )) //"HYMEL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment