# Bài tập 26/02
## Bài 1
Input: [“arp”, “live”, "strong,“sd3”], [“lively”, “alive”, “harp”, “sharp”, “armstrong”]
Output: [“arp”, “live”, “strong”]
```typescript=
let arr1 = ["arp", "live", "strong","sd3"]
let arr2 = ["lively", "alive", "harp", "sharp", "armstrong"]
function findCommonStringAppearInArr(arr1: string[], arr2: string[]):string[]{
let commonStringAppearInArr = arr1.filter(
value1 => arr2.filter(
value2 => value2.includes(value1)
).some(Boolean)
);
return commonStringAppearInArr;
}
console.log(findCommonStringAppearInArr(arr1, arr2));
```
Bài 2:
---
Input: "ams.AreaMaintain"
Output: "/area-maintain"
Input: "ams.BuildingAreaKanban"
Output: "/building-area-kanban"
```typescript=
function calssName2path(input:string):string {
let className:string = input.split(".")[1];
let words:string[] = className.split(/(?=[A-Z])/);
return "/" + words.map(m => m.toLocaleLowerCase()).join("-");
}
console.log(calssName2path("ams.AreaMaintain"));
console.log(calssName2path("ams.BuildingAreaKanban"));
```
Bài 3:
----
Input: ["flower","flow","flight"]
Output: "fl"
Input: ["dog","racecar","car"]
Output: ""
Input: ["dog", "frog", "log"] thí
Output: "og"
```typescript=
function findLongestCommonString(arr: string[]):string{
arr = arr.sort((a, b) => a.length - b.length); // more efficiency
// find candidates
let candidates = [];
for(let i = 1; i <= arr[0].length; i++){ // string length
for(let j = 0; j < arr[0].length - i + 1; j++) // start position
candidates.push(arr[0].slice(j, j+i));
}
// filter all appear in arr case
return candidates.filter(candidate => arr.every(m => m.includes(candidate)))
.sort((a, b) => b.length - a.length)[0];
}
console.log(
findLongestCommonString(["flower","flow","flight"])
)
console.log(
findLongestCommonString(["dog","racecar","car"])
)
console.log(
findLongestCommonString(["dog", "frog", "log"])
)
```