Count positive nd negative numbers in an array JavaScript solution #coding #softwaredeveloper #code

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

The task is about counting numbers of negative and positive. You don’t need any additional arrays here. Just an object with positiveCount and negativeCount

trushin
Автор

Or just...

const { positive, negative } = numbers.reduce(
(acc, cur) => {
acc[cur > 0 ? "positive" : "negative"].push(cur);
return acc;
},
{ positive: [], negative: [] },
);

Way less code and more performant.

narigoncs
join shbcf.ru