문제 링크 : String Matching in an Array
/**
* @param {string[]} words
* @return {string[]}
*/
var stringMatching = function(words) {
const result = []
words.forEach((e, i, origin) => {
let tempArr = [...origin]
tempArr.splice(i, 1)
if(tempArr.filter(el => el.includes(e)).length > 0) {
result.push(e)
}
})
return result
};
/**
* @param {string[]} words
* @return {string[]}
*/
var stringMatching = function(words) {
var arr = [];
for(i=0;i<words.length;i++){
for(j=0;j<words.length;j++){
if(words[i] !== words[j] && words[j].includes(words[i])){
arr.push(words[i]);
}
}
}
return [...new Set(arr)];
};