Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Nub remove the repeated elements of a list
- nub(X) -> nub(X, []).
- nub([], XUnique) -> XUnique;
- nub([X|Xs], XUnique) ->
- PositionWhereXFound = find(X, XUnique),
- if
- PositionWhereXFound > -1 ->
- nub(Xs, XUnique);
- true -> % 'else'
- nub(Xs, XUnique ++ [X])
- end.
- % Find the item in a list
- % Return the position where the first occurrence of Item is found
- % Otherwise, return -1
- find(_, []) -> -1;
- find(Item, X) -> find(Item, X, 0).
- find(Item, [Item|_Xs], Position) -> Position;
- find(Item, [_X|Xs], Position) -> find(Item, Xs, Position + 1);
- find(_, [], _) -> -1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement