Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops What are Loops?

Splitting sentence to see what word ends with the most common letter.

I am trying to find the letter that the most words in a sentence ends with and all the words that ends with that letter in the following variable. Jen Choi J Meacham Jason Anders Jason Anello Coen van Campenhout

Its my homework and I have tried the split function but it doesn't help and the slice function but it takes to long:.Based on the following variable:

\\\ var sentence = 'Down by the river there is a man that quiver and shiver, but he needs to deliver a packet that he think is a big racket and a packet of of gum.' \\\

1 Answer

Steven Parker
Steven Parker
231,275 Points

You forgot to show your work.

Split should work, but you may have forgotten that you need to remove the punctuation first or ignore it while splitting. Here's an example with a combination of both:

var words = sentence.replace(".","").split(/,? /);

Final answer: MostUsedEnding = "t" — ContributingWords = ["that", "but", "packet", "that", "racket", "packet"]