#! /usr/bin/perl use warnings; use strict; use List::Util qw{ sum0 }; sub cpsn { return unless @_; my @neg = grep $_ <= 0, @_; return @_ - @neg, sum0(@neg) } use Test::More tests => 5; is_deeply [cpsn()], []; is_deeply [cpsn(-1)], [0, -1]; is_deeply [cpsn(0, 0)], [0, 0]; is_deeply [cpsn(2)], [1, 0]; is_deeply [cpsn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15)], [10, -65];
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.
Discussion on: Daily Coding Puzzles - Oct 29th - Nov 2nd
Replies for: Monday Count of positives / sum of negatives (8 KYU): Return an array, where the first element is the count of positives numbers and the second ...
For further actions, you may consider blocking this person and/or reporting abuse