Codewars "Consecutive strings" kata The challenge description is as follows:

You are given an array 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.
Example:
longest_consec([&quot;zone&quot;, &quot;abigail&quot;, &quot;theta&quot;, &quot;form&quot;, &quot;libe&quot;, &quot;zas&quot;, &quot;theta&quot;, &quot;abigail&quot;], 2) 
--&gt; &quot;abigailtheta&quot;

n being the length of the string array, if n = 0 or k &gt; n or k &lt;= 0
return &quot;&quot;.

I solved the challenge with as a side goal to follow and use ECMAScript 6 as much as possible. All suggestions on improving the code are welcome!
Note: I did not like using k and n in code, so I used numStr and arrLen respectively.
const longestConsec = (strArr, numStr) =&gt; {
  const arrLen = strArr.length
  if (arrLen === 0 || numStr &gt; arrLen || numStr &lt;= 0) {
    return &quot;&quot;
  }
  const consecStrings = getAllConsecutiveStrings(strArr, numStr, arrLen)
  return getFirstLongestString(consecStrings)
}

const getAllConsecutiveStrings = (strArr, numStr, arrLen) =&gt; {
  const numConsecStr = arrLen - numStr
  const result = []
  let consecStr
  for (let i = 0; i &lt;= numConsecStr; i++) {
    consecStr = &quot;&quot;
    for (let s = i; s &lt; i + numStr; s++) {
      consecStr += strArr[s]
    }
    result.push(consecStr)
  }
  return result
}

const getFirstLongestString = strArr =&gt; {
  let firstlongestString = &quot;&quot;
  let longestLength = 0
  for (let str of strArr) {
    strLen = str.length
    if (strLen &gt; longestLength) {
      firstlongestString = str
      longestLength = strLen
    }
  }
  return firstlongestString
}
Some performance-related nitpicking:


Instead of string concatenation keep an array of string lengths;
Use a running window of current concatenated length: when advancing to the next string simply subtract the first window's element and add the current string length.


Thus the array will be iterated just once, no extra strings interned in the JS engine.

const longestConsec = (strings, count) =&gt; {
    let n = strings.length;
    if (!n || count &lt;= 0 || count &gt; strings.length)
        return '';

    let lengths = Array(n);

    // fill the running window
    let windowLen = 0;
    for (let i = 0; i &lt; count - 1; i++) {
        let stringLen = strings[i].length;
        windowLen += stringLen;
        // fill the cache with items 0..count-1, the rest will be filled in the main loop
        lengths[i] = stringLen;
    }

    let maxLen = 0;
    let maxLenAt = 0;
    for (let i = count - 1, windowStart = 0; i &lt; n; i++, windowStart++) {
        let stringLen = strings[i].length;
        lengths[i] = stringLen;

        let thisLen = windowLen + stringLen;
        if (thisLen &gt; maxLen) {
            maxLen = thisLen;
            maxLenAt = windowStart;
        }
        windowLen += stringLen - lengths[windowStart];
    }

    return strings.slice(maxLenAt, maxLenAt + count).join('');
}