我正在嘗試在HackerRank中使用Javascript處理項目euler#1。有人能給我提示我的代碼有什麼問題。結果總是爲零。項目euler#1,黑客等級
我跑我的功能在我的谷歌瀏覽器的控制檯,然後輸入我過程數據(10),它給了我23.我輸入過程數據(100),它給了我2318
當我嘗試使用我的代碼在從黑客等級的控制檯中,它輸出的結果爲零,就像它沒有通過第一個測試,它是0.
有沒有人試圖解決JavaScript中的hackerrank中的一些問題?
function processData(input) {
var result = []
var total=0
function findMultipleThreeAndFive(n){
var i = 0;
for(i ; i < n ;i++){
if(i%3 == 0 || i%5 == 0){
result.push(i);
}
}
}
findMultipleThreeAndFive(input)
function sum(){
for(var j = 0; j< result.length ;j++){
total += result[j]
}
return total;
}
sum()
console.log(total)
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function() {
processData(_input);
});
請解釋您在嘗試解決您的代碼時遇到的問題。它也有助於爲您的功能提供輸入。 –