aboutsummaryrefslogtreecommitdiff
path: root/challenge-059/mohammad-anwar/perl/ch-1a.pl
blob: 7be98d1233b33354e93cfd3cdaf363d8c8a31fea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl

use Test::More;
use Test::Deep;

is_deeply( split_list([ 1, 4, 3, 2, 5, 2 ], 3), [ 1, 2, 2, 4, 3, 5 ]);

done_testing;

sub split_list {
    my ($L, $K) = @_;

    my $before = [];
    my $after  = [];
    foreach my $i (@$L) {
        if ($i < $K) {
            push @$before, $i;
        }
        else {
            push @$after, $i;
        }
    }

    return [ @$before, @$after ];
}