@Islam777

JS. Почему Codewars выдает ошибку?

Вот задание:
Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).

For example,

[true, true, true, false,
true, true, true, true ,
true, false, true, false,
true, false, false, true ,
true, true, true, true ,
false, false, true, true]

The correct answer would be 17.

Hint: Don't forget to check for bad values like null/undefined

Вот мой код:
const countSheeps = arrayOfSheep => {
  let totalSheep = arrayOfSheep.reduce((accum, sheep) => {
    if (sheep === undefined || sheep === null) sheep === 0;
    return accum + sheep;
  }, 0);
  
  return totalSheep;
};


Что выводит TEST:
63b9208f4d717164573938.png
Что выводит ATTEMPT:
63b92111f1e7e569246450.png
  • Вопрос задан
  • 270 просмотров
Решения вопроса 1
Seasle
@Seasle Куратор тега JavaScript
Для начала это.
- if (sheep === undefined || sheep === null) sheep === 0;
+ if (sheep === undefined || sheep === null) sheep = 0;
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
30 апр. 2024, в 22:44
500 руб./в час
30 апр. 2024, в 21:45
20000 руб./за проект
30 апр. 2024, в 21:36
1500 руб./в час