的特性「長度」這是我得到了我的代碼中的錯誤:無法讀取零錯誤
TypeError: Cannot read property 'length' of null
at countPositivesSumNegatives
at /runner/frameworks/javascript/cw-2.js:179:21
at Promise._execute
at Promise._resolveFromExecutor
at new Promise
at describe
at Object.handleError
at ContextifyScript.Script.runInThisContext
at Object.exports.runInThisContext
的目標是創建一個函數,它在數字的隨機陣列(輸入),並返回正數的數量和負數的總和。一切正常,除了錯誤消息,我在上面得到,這是一個錯誤的價值觀測試,這意味着什麼
function countPositivesSumNegatives(input)
{
let negSum = 0;
let count = 0;
let arr = [];
for(i = 0; i < input.length; i++) {
if(input[i] > 0)
{
count++;
}
if (input[i] < 0)
{
negSum += input[i];
}
if (!input[i]) {
negSum = negSum;
count = count;
}
}
arr.push(count,negSum);
return arr;
}
}
通過'countPositivesSumNegatives(空)重現'。 – melpomene