Question concerning words to capitalize in Titleize method of Simon Says challenge - RSPEC Practice 1

Hey all,

I’m working through the RSPEC practice 1 challenges, and had a question concerning the Titleize method. The fourth spec is listed like this:

  1. Simon says titleize does capitalize ‘little words’ at the start of a title
    Failure/Error: expect(titleize(“the bridge over the river kwai”)).to eq(“The Bridge over the River Kwai”)

I understand the challenge, but I’m not sure how this can be handled without hardcoding specific words to ignore. The challenge says to not capitalize “little words” in titles unless they’re at the start of the title, but both “over” and “Kwai” have four characters. Unless the answer is simply to write a constant array consisting of prepositions, which a capitalize function would then ignore, I’m not sure how one would write a program that can tell the difference between “big” and “little” words. Telling the program to specifically ignore the word “over” and other prepositions doesn’t seem inherently programmatic.

If anyone has a more elegant solution to this problem, I’d be much obliged. Cheers!

1 Like

Hi Drew,

I think an array of exceptions is the best way to handle the more difficult cases and is not necessarily “hard coding.” Hard coding would be like:

return "The Bridge over the River Kwai" if title == "the bridge over the river kwai"

Keep up the great work!

Yeah it may have been helpful if the program lib or spec file specifically stated which words to consider as "little"
So I will give you a hint and tell you that the three words you need to keep lowercase unless at start of the string are [‘and’,‘the’,‘over’]

Got it, thanks for the clarification!