Counting Words with Prefixes
In this lab, you will be working on a function that can count the number of words that contain a given prefix. The objective is to implement a function named
prefixCount that receives an array of strings
words and a string
pref, and returns the number of strings in
words that have
pref as a prefix. A prefix of a string
s is any leading contiguous substring of
Consider the following examples to understand how the function should work:
Input: words = ["pay","attention","practice","attend"],
pref = "at"
Explanation: The 2 strings that contain "at" as a prefix are: "attention" and "attend".
Input: words = ["leetcode","win","loops","success"],
pref = "code"
Explanation: There are no strings that contain "code" as a prefix.
- 1 <= words.length <= 100
- 1 <= words[i].length, pref.length <= 100
- words[i] and
prefconsist of lowercase English letters.
In this lab, you will complete the following challenges:
- Implement the
prefixCountfunction with ESM import/export
- Export the
- Test the function with provided examples and additional test cases
For each challenge, the evaluation script will be testing your solution to ensure it meets the requirements. Make sure to export the necessary functions or variables in your code to be used by the evaluation script.