Solution:
function solution(S, K) {
const wordsLen = S.split(' ').map(word => word.length);
if (wordsLen.some(len => len > K)) return -1;
const lastIndex = wordsLen.length - 1;
let currentMessageLen = 0;
Solution:
function solution(S, K) {
const wordsLen = S.split(' ').map(word => word.length);
if (wordsLen.some(len => len > K)) return -1;
const lastIndex = wordsLen.length - 1;
let currentMessageLen = 0;