← Back to challenges

Same on Both Ends

JavaScriptHardstringsloopsregex

Instructions

Given a sentence, return the number of words which have the same first and last letter.

Examples

countSameEnds("Pop! goes the balloon") ➞ 1

countSameEnds("And the crowd goes wild!") ➞ 0

countSameEnds("No I am not in a gang.") ➞ 1

Notes

  • Don't count single character words (such as "I" and "A" in example #3).
  • The function should not be case sensitive, meaning a capital "P" should match with a lowercase one.
  • Mind the punctuation!
  • Bonus points indeed for using regex!
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.