Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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