-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.unique.fmfn
59 lines (46 loc) · 2.09 KB
/
list.unique.fmfn
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Purpose: Removes duplicate values from the list.
Returns: Text
Name: list.unique ( values )
Parameters: ( values ) list = FileMaker List ( return delimited list )
Dependencies: NONE
2011-08-24, JPS, Created.
2011-09-23, JPS, Updated to work with lists where only the last lines are
duplicated.
2012-09-17, JPS, Complete rewrite, the function would not work properly with lists that
had lines with characters that were inside others (e.g. 1 and 11).
2012-09-18, JPS, caseSensitive has been depreciated, left in place for backwards compatibility.
2012-09-20, JPS, Renamed the global variable ($$VALUES.UNIQUE.LIST), to use a global namespace.
2012-10-02, JPS, Completely removed caseSensitive.
2012-11-13, JPS, Changed the global variable ($$FUNCTION.UNIQUE.LIST.RESULTS), to local variables ($FUNCTION.UNIQUE.LIST.RESULTS.
2012-12-05, JPS, Updated the result of an empty list to output nothing instead of a question mark.
2013-07-31, JPS, Updated so that the trailing return is removed.
*/
Let (
[
values = Trim ( values );
theCount = ValueCount ( values );
firstValue = LeftValues ( values ; 1 );
//Check to see of the value is in the global list
duplicate = If ( IsEmpty ( FilterValues ( $FUNCTION.UNIQUE.LIST.RESULTS ; firstValue )); False; True );
//If it is not a duplicate add to list
$FUNCTION.UNIQUE.LIST.RESULTS = If ( duplicate; $FUNCTION.UNIQUE.LIST.RESULTS; $FUNCTION.UNIQUE.LIST.RESULTS & firstValue );
remainingValues = RightValues ( values ; theCount - 1 );
remainingValues = Left ( remainingValues; Length ( remainingValues ) - 1 )
];
Case (
theCount = 0;
"";
theCount = 1;
Let (
[
theList = $FUNCTION.UNIQUE.LIST.RESULTS;
theList = Left ( $FUNCTION.UNIQUE.LIST.RESULTS; Length ( $FUNCTION.UNIQUE.LIST.RESULTS ) - 1 );
//Clear the global
$FUNCTION.UNIQUE.LIST.RESULTS = ""
];
theList);
//Default
list.unique ( remainingValues )
)
)