I've been training on the CodeWars site and I should have done following exercise:(我已经在CodeWars网站上接受培训,并且应该做以下练习:)
function solution(str){ var result = []; if((str.length % 2) === 0) { for (var i = 0; i < str.length; i + 2){ result.push(str.substr(i, 2)); } } else { for (var i = 0; i < (str.length); i + 2){ result.push(str.substr(i, 2)); } result.push(str.substr(str.length - 1, 1) + '_'); }; return result; };
Your for loops are wrong.(您的for循环是错误的。)
i
i += 2
for (let i = 0; i < (str.length); i += 2)
2.1m questions
2.1m answers
60 comments
57.0k users