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:
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.
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.