Difference between revisions of "ListUnique"

From Second Life Wiki
Jump to: navigation, search
(New page: {{LSL Header}} __NOTOC__ <div id="box"> == Function: list ListUniq(list {{LSL Param|lAll }}; == <div style="padding: 0.5em;"> Given a list of elements, strips out duplicates in tha...)
 
Line 1: Line 1:
 
{{LSL Header}} __NOTOC__
 
{{LSL Header}} __NOTOC__
 
<div id="box">
 
<div id="box">
== Function: [[list]] ListUniq([[list]] {{LSL Param|lAll }}; ==
+
== Function: [[list]] ListUnique([[list]] {{LSL Param|lAll }}; ==
 
<div style="padding: 0.5em;">
 
<div style="padding: 0.5em;">
 
Given a list of elements, strips out duplicates in that list.
 
Given a list of elements, strips out duplicates in that list.
  
 
<lsl>
 
<lsl>
list ListUniq( list lAll ) {
+
list ListUnique( list lAll ) {
 
     integer i;
 
     integer i;
 
     list lFiltered = llList2List(lAll, 0, 0);
 
     list lFiltered = llList2List(lAll, 0, 0);
Line 23: Line 23:
 
Example:<br />
 
Example:<br />
  
list mylist = ListUniq(["A", "A", "B", "C", "C", "B"])
+
list mylist = ListUnique(["A", "A", "B", "C", "C", "B"])
  
 
would return the list:
 
would return the list:
Line 33: Line 33:
  
  
{{LSLC|Examples|ListXUniq}}
+
{{LSLC|Examples|ListXUnique}}

Revision as of 15:40, 12 July 2008

Function: list ListUnique(list lAll;

Given a list of elements, strips out duplicates in that list.

<lsl> list ListUnique( list lAll ) {

   integer i;
   list lFiltered = llList2List(lAll, 0, 0);
   integer iAll = llGetListLength( lAll );
   for (i = 1; i < iAll; i++) {
       if ( llListFindList(lFiltered, llList2List(lAll, i, i) ) == -1 ) {
           lFiltered += llList2List(lAll, i, i);
       }
   }
   return lFiltered;

}

</lsl>


Example:

list mylist = ListUnique(["A", "A", "B", "C", "C", "B"])

would return the list:

["A", "B", "C"]