Skip to content

Commit

Permalink
Compress lists
Browse files Browse the repository at this point in the history
  • Loading branch information
zmack committed Dec 8, 2010
1 parent f96d526 commit 1ee092b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion first.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-module(first).

-export([last/1, last_two/1, item_at/2, length/1, reverse/1, flatten/1]).
-export([last/1, last_two/1, item_at/2, length/1, reverse/1, flatten/1, compress/1]).

last([]) ->
empty;
Expand Down Expand Up @@ -51,3 +51,13 @@ flatten([Head|Tail], List) ->
[Head|flatten(Tail, List)];
flatten([], List) ->
List.

compress(List) ->
compress(List, empty).

compress([Head|Tail], Last) when Head == Last ->
compress(Tail, Head);
compress([Head|Tail], _Last) ->
[Head|compress(Tail, Head)];
compress([], _) ->
[].

0 comments on commit 1ee092b

Please sign in to comment.