Skip to content

Instantly share code, notes, and snippets.

@rvbsanjose
Forked from scottchiang/pseudocode
Created October 2, 2012 21:51
Show Gist options
  • Save rvbsanjose/3823543 to your computer and use it in GitHub Desktop.
Save rvbsanjose/3823543 to your computer and use it in GitHub Desktop.
pseudocode
Script: CONVERT EVERY OTHER LETTER OF A SENTENCE TO CAPITAL LETTERS
GET a sentence from user input
IF the word starts with a capital letter, don't change it
ELSE convert every other letter to capital letters
ENDIF
PRINT the formatted sentence
def new_pseudo
sentence = gets.chomp
if sentence.start_with?(sentence[0].upcase)
sentence
else
words = sentence.split(' ')
words.each do |word|
(1..word.length - 1).step(2) do |index|
word[index] = word[index].upcase
end
end
words.join(' ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment