I like your approachπ Thanks for sharing itπ I though about reduce, but for some reasons didn't give it a shot.
But this solution won't pass the tests. It'll always return [0, 0] I assume you made a few typos, it happens to me all the time))
I'd change it like this:
function countPositivesSumNegatives(input) { return (input && input.length) ? input.reduce(([pSum, nSum], curr) => [pSum += (curr >= 1 && 1), nSum + Math.min(0, curr)], [0, 0]) : []; }
I think it might look like this.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like your approachπ Thanks for sharing itπ
I though about reduce, but for some reasons didn't give it a shot.
But this solution won't pass the tests. It'll always return [0, 0]
I assume you made a few typos, it happens to me all the time))
I'd change it like this:
I think it might look like this.