Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
function solution(str){ let arr = str.split(/(..)/g).filter(str=>str); if (arr[arr.length - 1].length === 1){ arr[arr.length - 1] += "_" } return arr }
TypeError: Cannot read properties of undefined (reading 'length')
arr = []; (arr.length - 1) = -1 arr[arr.length - 1] = arr[-1] = undefined arr[arr.length - 1].length = undefined.length = Error
solution() Uncaught TypeError: Cannot read properties of undefined (reading 'split') solution("") Uncaught TypeError: Cannot read properties of undefined (reading 'length') solution("1") ['1_'] solution("12") ['12'] solution("123") (2) ['12', '3_'] solution("1234") (2) ['12', '34'] solution("12345") (3) ['12', '34', '5_']