← Back to challenges

Prefixes vs. Suffixes

JavaScriptHardstringsregexvalidation

Instructions

Create two functions: isPrefix(word, prefix-) and isSuffix(word, -suffix).

  1. isPrefix should return true if it begins with the prefix argument.
  2. isSuffix should return true if it ends with the suffix argument.

Otherwise return false.

Examples

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

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

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

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

Notes

The prefix and suffix arguments have dashes - in them.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Hiding the Card Number