Created
April 18, 2014 01:03
-
-
Save charliepark/11019736 to your computer and use it in GitHub Desktop.
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
function test(candidate){ | |
return candidate === passing; | |
} | |
var sentence = "The quick brown fox jumps."; | |
var passing = "Jumps fox brown quick the."; | |
function turnaround(sentence){ | |
sentence = sentence.toLowerCase().replace('.','').split(' '); | |
sentence = sentence.reverse().join(' ')+"."; | |
sentence = sentence[0].toUpperCase() + sentence.slice(1,sentence.length); | |
return sentence; | |
} | |
var candidate = turnaround(sentence); | |
test(candidate); | |
var sentence = "The quick brown fox -- Mr. Fennec -- jumps."; | |
var passing = "Jumps -- Fennec Mr. -- fox brown quick the."; | |
function turnaroundWithCapsAndPunctuation(sentence){ | |
sentence = sentence.slice(0, sentence.length - 1).split(' '); | |
sentence[0] = sentence[0].toLowerCase(); | |
sentence = sentence.reverse().join(' ') + "."; | |
sentence = sentence[0].toUpperCase() + sentence.slice(1,sentence.length); | |
return sentence; | |
}; | |
var candidate = turnaroundWithCapsAndPunctuation(sentence); | |
test(candidate); | |
var sentence = "The quick brown fox -- Mr. Fennec -- jumps?"; | |
var passing = "Jumps -- Fennec Mr. -- fox brown quick the?"; | |
function turnaroundWithCapsAndKeepingPunctuation(sentence){ | |
var punctuation = sentence[sentence.length - 1]; | |
sentence = sentence.slice(0, sentence.length - 1).split(' '); | |
sentence[0] = sentence[0].toLowerCase(); | |
sentence = sentence.reverse().join(' ') + punctuation; | |
sentence = sentence[0].toUpperCase() + sentence.slice(1,sentence.length); | |
return sentence; | |
}; | |
var candidate = turnaroundWithCapsAndKeepingPunctuation(sentence); | |
test(candidate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment