DAY42:Consecutive strings


Posted by birdbirdmurmur on 2023-08-24

題目連結

https://www.codewars.com/kata/56a5d994ac971f1ac500003e

解法

function longestConsec(strarr, k) {
    if (k <= 0 || strarr.length === 0) {
        return '';
    }

    let long = ''
    for (let i = 0; i < strarr.length - k + 1; i++) {
        const currString = strarr.slice(i, i + k).join('')
        if (currString.length > long.length) {
            long = currString
        }
    }
    return long
}

筆記


#javascript #Codewars







Related Posts

Meet 創業小聚 2021.2.24

Meet 創業小聚 2021.2.24

物件傳值 與 物件傳參考

物件傳值 與 物件傳參考

JavaScript 數據類型 & 內存

JavaScript 數據類型 & 內存


Comments