Задача с codewars:
Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative.
If the input is an empty array or is null, return an empty array.
Example
For input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15], you should return [10, -65].
Это код который проходит прверкуfunction countPositivesSumNegatives(input) {
let countPositive = 0;
let sumNegative = 0;
if (input == null) {
return []
}
if (input.length == 0) {
return []
}
input.forEach((elem) => {
if (elem > 0) {
countPositive++
} else {
sumNegative += elem;
}
});
return [countPositive, sumNegative]
}
Но если поменять местами проверки input == null и input.length == 0, их тест выдает ошибку проверки на null. Почему так?