DEV Community

Discussion on: Daily Coding Puzzles - Oct 29th - Nov 2nd

Collapse
 
choroba profile image
E. Choroba
#! /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];