Back to all solutions

#1967 - Number of Strings That Appear as Substrings in Word

Problem Description

Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word.

A substring is a contiguous sequence of characters within a string.

Solution

/**
 * @param {string[]} patterns
 * @param {string} word
 * @return {number}
 */
var numOfStrings = function(patterns, word) {
  return patterns.reduce((count, pattern) => word.includes(pattern) ? count + 1 : count, 0);
};