Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- DB2
- isSquare
- react
- type
- TABLESPACE
- JDBC
- react hook
- TypeScript
- codewar
- manifest.json
- IBM
- custom hook
- descendingOrder
- java api
- Debug
- useEffect
- codewars
Archives
- Today
- Total
taesik
Consecutive strings 본문
You are given an array(list) strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array.
export function longestConsec(strarr: string[], k: number): string {
if (strarr.length === 0 || k > strarr.length || k <= 0) {
return "";
}
return strarr
.reduce((defender, _, idx, target) => {
const challenger = target.slice(idx, idx + k).join("");
return challenger.length > defender.length ? challenger : defender;
}, "");
}
'functions and trick > typescript_javascript' 카테고리의 다른 글
Counting Duplicates (0) | 2022.01.29 |
---|---|
Backspaces in string (0) | 2022.01.29 |
digitRoot (0) | 2022.01.29 |
Coordinates Validator (0) | 2022.01.28 |
Count Friday 13th given year (0) | 2022.01.28 |