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

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

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

countAdverbs("He hates potatoes.") ➞ 0

countAdverbs("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.