Prefixes vs. Suffixes

Published by Helen Yu in

Create two functions: is_prefix(word, prefix-) and is_suffix(word, -suffix).

  1. is_prefix should return true if it begins with the prefix argument.
  2. is_suffix should return true if it ends with the suffix argument.

Otherwise return false.

Examples

is_prefix("automation", "auto-") ➞ true

is_suffix("arachnophobia", "-phobia") ➞ true

is_prefix("retrospect", "sub-") ➞ false

is_suffix("vocation", "-logy") ➞ false

Notes

The prefix and suffix arguments have dashes - in them.

Watch a quick demo on how Edabit works.