Hack Frontend Community

Find Strings with Substring

Avito
Write a function findSubstring(substring, arr) that takes a string substring and an array of strings arr, and returns an array of strings that contain the substring substring.
  • - The substring must be found anywhere in the string.
  • - Character case matters (case-sensitive).
  • - If no string contains the substring, return an empty array.

Examples:

Input 1: "oo", ["food", "door", "moon"]
Output 1: ["food", "door", "moon"]
Input 2: "xyz", ["apple", "banana", "cherry"]
Output 2: []
Run your code to see results.