-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSolution.js
35 lines (33 loc) · 851 Bytes
/
Solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//https://leetcode.com/problems/string-matching-in-an-array/
/**
* @param {string[]} words
* @return {string[]}
*/
var stringMatching = function (words) {
let arr = [];
words.forEach(searchword => {
words.forEach(word => {
if (searchword != word) {
if (searchword.search(word) >= 0) {
if (!arr.includes(word)) {
arr = [...arr, word]
}
}
}
})
})
return arr;
};
/*
Input: words = ["mass","as","hero","superhero"]
Output: ["as","hero"]
Input
["leetcoder","leetcode","od","hamlet","am"]
Output
["leetcode","od","od","am"]
Expected
["leetcode","od","am"]
*/
let words = ["mass", "as", "hero", "superhero"];
words = ["leetcoder", "leetcode", "od", "hamlet", "am"];
console.log(stringMatching(words))