[CodeWars] Consecutive strings

Consecutive strings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function longestConsec(strArr, k) {
const n = strArr.length;
let currentLongStr = '';

if (n === 0 || k > n || k <= 0) {
return '';
}

for (let i = 0; i < n; i++) {
const loopStr = strArr.slice(i, k + i).join('');
if (loopStr.length > currentLongStr.length) {
currentLongStr = loopStr;
}
}
return currentLongStr;
}
Share