Counting Adverbs

Published by Helen Yu in

Create a function that counts the number of adverbs in a sentence. An adverb is a word that ends with ly.

Examples

count_adverbs("She ran hurriedly towards the stadium.") ➞ 1

count_adverbs("She ate the lasagna heartily and noisily.") ➞ 2

count_adverbs("He hates potatoes.") ➞ 0

count_adverbs("He was happily, crazily, foolishly over the moon.") ➞ 3

Notes

  • Do NOT count words where the ly is in the beginning or the middle (e.g. Lysol, Illya).
  • For the purpose of this exercise, ignore the nuances of the English language (some adjectives also end in ly).
Watch a quick demo on how Edabit works.