Back to all solutions
#1408 - String Matching in an Array
Problem Description
Given an array of string words. Return all strings in words which is substring of another word in any order.
String words[i] is substring of words[j], if can be obtained removing some characters to left and/or right side of words[j].
Solution
/**
* @param {string[]} words
* @return {string[]}
*/
var stringMatching = function(words) {
return words.filter(s => words.some(word => word !== s && word.includes(s)));
};