这里的脚本初学者。我正在尝试代码战(挑战)卡塔。它一直告诉我,我的解决方案不起作用,我想知道为什么。如何修复代码以使其正常工作?以下是问题的内容。
"Complete the solution so that it returns the greatest
sequence of five consecutive digits found within the number given."
"1234567890" - 67890 is the greatest sequence of 5 consecutive digits.
链接到卡塔:https://www.codewars.com/kata/51675d17e0c1bed195000001/train/javascript
我的代码:
function solution(digits){
digits = +digits.split('');
let solution = 0;
for (let i = 0; i < digits.length; i++) {
let pending = digits[i] + digits[i+1] + digits[i+2] + digits[i+3] + digits[i+4];
if (pending > solution) {
solution = pending;
}
}
return solution;
}
最佳/最解释的答案将获得绿色复选标记。让我知道我的解决方案有点多余也不会有什么坏处 谢谢!
万千封印
相关分类