Url Truncation | Pastebin | Bookmarklet Home | History | Help | Sign In

na.nu

Syntax: Erlang

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
%% API Function
sieve(ListOfPaths) ->
        sieve(lists:sort(ListOfPaths), []).

%% Internal Function
sieve([A,B|Tail], Acc) ->
        case string:str(B,A) of
                0 -> sieve([B|Tail], [A|Acc]);
                _ -> sieve([B|Tail], Acc)
        end;
sieve([A], Acc) ->
        lists:reverse([A|Acc]);
sieve([], []) ->
        [].

%% Test Function
test() ->
        Paths = ["/foo", "/qux/wibble", "/foo/bar/baz", "/qux", "/foo/bar"],
        io:format("Paths:  ~p~n", [Paths]),
        SPaths = sieve(Paths),
        io:format("SPaths: ~p~n", [SPaths]),
        ["/foo/bar/baz","/qux/wibble"] = SPaths,
        ok.