Returns the unique items in a table

I would like to know how to get combanations of any table without repetitions of the same elements in a different order.

The table is made of properties of the object and could have a variable number of elements.

In other words, if I have an array of 2 elements for example

[a, b]

I want to receive 3 new arrays of void

(1) [a]

(2) [b]

(3) [a, b]

I don't want to receive [b, a] as having the same elements as [a, b] only in a different order.

Well, if there just 2 items in the table then it's pretty easy, but when there is more then I do not understand!

An array of 4 elements for example

[a, b, c and d]

would need to produce a new table of the following tables 15 sub

(1) [a]

(2) [b]

(3) [c]

(4) [d]

(5) [a, b]

(6) [a, c]

(7) [a, d]

(8) [b, c]

(9) [b, d]

(10) [c, d]

(11) [a, b, c]

(12) [a, b, d]

(13) [a, c and d]

(14) [b, c and d]

(15) [a, b, c and d]

A table of 5 elements would give me overtime 24 tables and so forth.

I tried many ways with diddlysquat results

Slice, splice and all things nice!

If someone of you could share this trade secret with me, I would appreciate it a lot.

Trevor

Nice challenge!

We could try this:

function arrayParts(/*arr*/a, r,i,j,t,s,p)
// -------------------------------------
// Note: a is supposed to contain unique items
// [if necessary, apply a makeUnique routine first]
{
    if(! (i = Math.pow(2,a.length)-1) ){ return null; }
    (r=[]).toString = function(){return this.join('\r');};

    while(i--)
        {
        r[i] = t = [];
        s = (1+i).toString(2);
        p = (j=s.length) - 1;
        while( j-- ) '1'==s[j] && t[t.length]=a[p-j];
        }

    // Reorder by length [if needed!]
    // ---
    r.sort( function(x,y){return x.length-y.length;} );

    return  r;
}

// Sample code
// ---
var arrTest = ['Blue','Red','Yellow','Green','Black'];
alert( arrayParts(arrTest) );

Really not optimized, but it was pretty fun to write ;-)

@+

Marc

Tags: InDesign

Similar Questions

  • kindly tell how to use the unique value of a table with the index 0

    kindly tell how to use the unique value of a table with the index 0

    Hi
     
    Yep, use Index Array as Gerd says. Also, using the context help ( + h) and looking through the array palette will help you get an understanding of what each VI does.
     
    This is fundamental LabVIEW stuff, perhaps you'd be better spending some time going through the basics.
     
    -CC
  • How to select the next item in a table view?

    Hey,.
    I want to select the next item, but I have no idea about it? have you any suggestions?
    for example:
    the second element is currently selected, I need to select the third in my code, how can I implement this feature?
    private IntegerProperty index = new SimpleIntegerProperty();
    
        public final double getIndex() {
            return index.get();
        }
    
        public final void setIndex(Integer value) {
            index.set(value);
        }
    
        public IntegerProperty indexProperty() {
            return index;
        }
    

    Get the selected item:

    table.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
    
                @Override
                public void changed(ObservableValue observable, Object oldvalue, Object newValue) {
                    Person selectedPerson = (Person) newValue;
                    setIndex(data.indexOf(newValue));
    
                }
            });
    

    Select the following index:

    table.getSelectionModel().select(index.get() +1  );
    
  • Search for the missing items on 2 tables

    Hi all

    Basically I have following 4 tables (including two lookup tables)

    My intention is initially essentially needs to know what are the matching records
    between ModTab and MedTab through key binding (ItemID & TrfCode through Lookup1), and then
    lack of OptCodes in MedTab located in ModTab and vice versa.

    I can do this with only once

    Key fields are one with the same name.

    When link MedTab and the Lookup2 must use StateCode both CodeOption



    ModTab
    ======
    Component
    Item ID



    MedTab
    ======
    TrfCode
    CodeOption
    StateCode



    Lookup1
    =======
    Item ID
    TrfCode


    Lookup2
    ========
    Component
    StateCode
    CodeOption


    How can I do



    Appreciate your guidance


    See you soon


    Sexy

    Vanessa wrote:
    I can do this with only once

    Surely,.

    select *
    from ModTab
    join Lookup1 on Lookup1.Item_id = ModTab.Item_id
    join MedTab on MedTab.TrfCode = Lookup1.TrfCode
    left join Lookup2 on Lookup2.OptCode = MedTab.OptCode and Lookup2.StateCode = MedTab.StateCode
    where Lookup2.StateCode is null
    
  • return the minimum value from a table

    Hi all, how can I output the lower value within an array of numbers?

    I have this but it does not work, it is always the first number in the table.

    function minF(a:Array):Number {var min:Number = [0];      for (var i: Number = 1; i >.) Length; i ++) {if (a [i] > min) {min = a [i];}           } else {trace ("buahMin!");           return min}}; }

    Thanks to you all.

    This is because you have the sign on your conditional loop wrong.

    You must make the comparison for all I less than your length of array.

    function minF(a:Array):Number {}

    var min:Number = [0];

    for (var i: Number = 1; i

    min (min =

    }

    return min;

    }

  • How to diagnose ITS do not return the content items in search results

    I have a WCC with configured SESCrawlerExport instance. It produces a stream for a few pieces of sample content. This works well.

    I installed ITS and configured to analyze the content server using the power that precedes. It works very well.

    ITS retail and synthesized crawler page statistics shows that the 4 pieces of content have been analyzed successfully. It is as expected.

    However, when I try to search for one of these elements, none are returned.

    How can I solve this problem?

    Hello

    I use ITS content and webcenter portal. I met a good number of questions related to the content server and ITS creepy.

    To answer you question please check the details below.

    1. check step by step - after race sescrawlerexport datafeed check the particular folder will be created in ucm/cs/data/sescrawlexport directory and particular file.

    2 - you update of the document get indexed means. your content server crawler settings are adequate. If the settings are correct an xml file generated in the same directory

    http://192.168.56.1:16200/cs/idcplg? IdcService = SES_CRAWLER_STATUS & IsJava = 1 & source = content & StatusFeed =]] >

    controlFeed

    content

    attributeBased

    3 - run robot and check the document get indexed. You can check by using the content server.

    4 - What authorized person you use in robot content server configuration? Please check the appropriate settings. Sometimes it is cause trouble. Please check option access control list

    5. After you find some content. Check logs search_server1_diagnostics logs. Maybe you encounter permission-related issues.  Please check again identity management parameters are specific.

    Thank you

    Amey

  • Create the new table entry by moving the corresponding items from another table

    I have an application where employers create permit applications. Once all the information collected and verified, this request is approved, removed from the 'application' table and added to the table, "license". I have a button called "approve this request. Is it possible to copy the data corresponding table elements 'request' to the 'table of permit"after selecting the button approve?

    This should be relatively simple to implement.
    You can create a process of pl/sql page ' on submit ' which puts the fire on the "Approve" button The code for the process would be something like

    insert into permit_table(col1,col2,col3...)
    select 
    

    CITY

  • Photosmart 5520 transforms the unique items in several separate files when scanning to the imac

    My 5520 when scanning for my imac (on OSX10.6.8) wireless began to separate a page I'm scanning in several separate files that contain certain words or images, but not all of the content. I have reset to factory settings, but the problem remains the scanner are useless. Can someone help me set it up so it parses everthing on the page in one file please?

    Hello
    The default analysis workflows configured to detect separate elements. don't forget to change the scanning settings to not crop the area swept as follows:

    1 open the HP utility and select your device.
    2. based on Scan Settings open the "Scan to Computer".
    3. click on the tab "scan tasks.
    4. Select the shortcut Scan allows to analyze, and then click on edit.
    5. in the section of scanning from an HP device, click the blue triangle or button view details to expand the menu.
    6. in the expanded menu now, open the drop down next to cultures in and set as none.
    7. click OK and try to scan the image.

    Kind regards
    Shlomi

  • Custom code to return all the selected items in a dynamic list

    Does anyone know of a custom code to return all the selected items in a dynamic list? Support told me that Dreamweaver does not return the last item. If anyone can give me a Tips how make this code custom or can direct me to code, I would be eternally grateful.

    Thanks to you two. I used the square brackets since they are in this season...

    No,

  • How does the APEX 5 'Refresh' Action? Unable to refresh the page items.

    Hello

    I'm 5 APEX developed a page with both regions. Goal is to show the number of cells on the main area and allow to update the same number of cells from another region on the same page.

    Region 1: Added a view-only point P2_CELL_NUMBER_SHOW seen source of sql return the unique value. Like "Select cell_number of user_cell."

    Region 2 (hide this region during the loading of the page): adding an item of text P2_CELL_NUMBER_UPDATED. This region has added a button "Apply Changes". During the click on added dynamic actions in the following order:

    (a) PLSQL: Null; Submit article: P2_CELL_NUMBER_UPDATED

    (b) PLSQL: the UPDATE call sql statement to update the number of cells in the database table.

    (c) masking region 2 and region 1 via java script list.

    (d) refresh region 1 (here I expect at this point P2_CELL_NUMBER_SHOW should show the new update on the step value b). But get the old value that was earlier on region 1. But when submitting the page then region 1 get the new value.

    So, does send the page or set the session state to get the new value on region 1? Will update no help in this situation?

    Thank you

    Ankit

    Hi Pierre,.

    The dynamic Action of the type "Refresh", does not work on the elements and entry areas with elements of entry. It is intended for regions of report with PPR (partial Page Refresh) allowed namely interactive reports, classic and graphic regions.

    Kind regards

    Kiran

  • Get random items, no repetitive table

    Hello!

    I'm doing a 20-question, multiple-choice quiz. Each question is chosen at random in a table, and whenever the user clicks on the right answer, another random question comes up. I was not able to find a way to make sure not to repeat issues already selected. I tried to push the selected items in a table, then using $.grep and an if statement to check if the other randomly chosen question is already in the new table or not, but I couldn't get that to work.

    My code in the Panel of compositionReady is:

    var arr is ["Symbol_1", 'Symbol_2', 'Symbol_3', 'Symbol_4', 'Symbol_5', 'Symbol_6', 'Symbol_7', 'Symbol_8', 'Symbol_9', 'Symbol_10', 'Symbol_11', 'Symbol_12', 'Symbol_13', 'Symbol_14', 'Symbol_15', 'Symbol_16', 'Symbol_17', 'Symbol_18', 'Symbol_19', 'Symbol_20'];.

    sym.setVariable ("arr", arr);

    arr.sort (Function () {return 0.5 - Math.random ()});

    arr. Length = 20;

    var c = Math.floor (Math.random () * 100) %arr.length;

    for (i = 0; i < 20; i ++) {}

    SYM.$(arr[i]). Hide();

    SYM.$(arr[ques]). Show();

    };

    and whenever you click on the right answer, I run this:

    sym.getComposition () .getStage ().$("try_again1").hide ();

    sym.getComposition () .getStage ().$("correct1").show ();

    sym.getComposition () .getStage ().getSymbol("correct1").play ();

    var arr = sym.getComposition () .getStage () .getVariable ("arr");

    var c = Math.floor (Math.random () * 100) %arr.length;

    for (i = 0; i < = 20; i ++) {}

    sym.getComposition () .getStage ().$(arr[i]).hide ();

    sym.getComposition () .getStage ().$(arr[ques]).show ();

    }

    An overview of this would be much appreciated!


    Hi, bettiesac212-

    Well, I took a quick glance to your project (including project files was very useful, which is said by the way).  So what happens, is that you have included my code snippet in the middle of all the other things happening in your file.  There are a lot of questions I had looking at your code, like:

    • What is 'e '?  Where did this come from?
    • Why did you an array.sort initially?
    • Why do you attribute arr.length?  It is a property of arr already, so there is no reason to assign this

    Anyway, I cleaned up the code a bit to my snippet in.  I left some of her "as an exercise to the student", to paraphrase some of my old books, but I hope the console log will show you that usedArr is now a random picture that you can save.  If you save a variable that has the index, (aka "what question am I on?"), then you can get where you are now, add one, save this variable and are looking for the next item in usedArr and know that it is properly randomized.

    For those who are looking for an answer, this is the code I ended up using:

    var usedArr = new Array();

    var currentIndex = 0;

    While (currentIndex< 20)="">

    var randNum is Math.floor ((Math.random () * 100)) % 20;.

    If (usedArr [randNum] == undefined) {}

    We can place an object!

    usedArr [randNum] = arr [currentIndex];

    currentIndex ++;

    }

    by do not increment the currentIndex, we force basically he draw again

    }

    for (i = 0; i< usedarr.length;="" i++)="">

    Console.log ("index usedArr" + i + ":" + usedArr [i]);

    }

    You can save your new table and just browse each time

    you say "next question."

    I think that's more or less what I posted in my previous answer.  Bettie, I'll send you a link to your project files via private message in a few minutes.

    Thank you

    -Elaine

  • Simply extract the unique rows in table 2d

    Hello, I'm sorry for my English. I have a chart 2D with thousends of rows and 2 columns. I want to extract only the unique rows in the table. So I need to exclude all lines have that / which (?) duplicate (s) and exclude the duplicate (s) too.

    Simple example:

    Input array:


    0 0 ---> single

    0 1 ---> D1

    1 0 ---> single

    1 1 ---> D1

    0 1 ---> D2

    2 0 ---> single

    1 1 ---> D2

    2 0 ---> D1

    1 1 ---> D3

    2 0 ---> D2

    2 2 ---> unique

    Desired output table:


    0 0

    1 0

    0 2

    2 2

    Can someone help me?

    Hi Werty,

    To do this is to compare each line with the entire table and count the number of matches.

    If there is only a single match, then the line is unique.

    Here is an example:

    Outside for the index of the loop through each line.

    Inside of the loop compares each line with the entire table and counts the matches.

    Then, a check is made to see if this line is unique.

    The case statement adds unique lines in the output array.

    Note: Use a table function build in a loop like this could cause problems if there will be a large number of unique lines.

  • Returns the selected table column header

    I don't know there is probably a way to do this.  But I have not yet found.

    I am building an application that will act as a sort of "universal" reports generator for a MySQL database tables.

    At startup, a drop-down list box is filled with the names of tables in the database.  When the user selects one of these tables, the column names are taken from the base and used to fill the column headers for the table of LabVIEW.

    The idea is that the user can select this column and enter the constraints of filter in a text box.  These constraints will then be added to the WHERE statement for this column.

    So far I've been able to find a way to return the Active cell or a selection of cells, when the user clicks on the actual data of the table.

    Is there a direct way to retrun a selected in LabVIEW column header value?

    I am dreaming that there may be some sort of workaround using transparent controls over the headers.  But because different tables will have a different number of columns that the user defines the width, I'm not really sure that it will work more.

    If you the editable headers, this allows Active cells specify that your column is - 1 column selected active line is the selected column. You may need to use the mouse down? to filter the possibility for the user to change the right column headings.

  • put an item into the basket, made an empty recycle bin, need return the item, please help, I did nothing since the drain, so the machine is in the same condition as when I emptied

    put an item into the basket, made an empty recycle bin, need return the item, please help, I did nothing since the drain, so the machine is in the same condition as when I emptied

    If you have xp, you can do system restore

  • GetCurrentRow returns the null value while trying to values defined in table advanced VO

    Hi all

    I'm trying to set default values to a bean advanced table according to the selection of LOV in another region. Here is the code and getCurrentRow returns the value null and null pointer exception is throwed. Please let me know where Iam going bad.

       if (pageContext. ) isLovEvent ())

    LovInputSourceId = string pageContext. getLovInputSourceId ();

       if ("poNumber". ) is equal to ()lovInputSourceId))

    pageContext . putDialogMessage (new OAException()"inside Onclick"));

    OAViewObject VO = (OAViewObject) am . findViewObject ()"L3APNonprojbasedpoVO1");

    VO1 OAViewObject = (OAViewObject) am . findViewObject ()"L3APCodingInfoEOVO1");

      VO . setWhereClause (null);

      VO . setWhereClauseParams (null);

      VO . executeQuery ();

      VO1 . setWhereClause (null);

      VO1 . setWhereClauseParams (null);

      VO1 . setWhereClause ("1=2");

      VO1 . executeQuery ();

       if (null! = VO )

       Row ReqRow = (Row) VO.first();  

       if (null ! = ReqRow )

       int idx = VO . getRowCount ();

       for (int xx = 0; xx < idx ; xx ++)

    String Description = (String)VO. getCurrentRow (). getAttribute ()"ItemDescription");

       Number Amount = (Number)VO. getCurrentRow (). getAttribute ("Amount");

       String Company = (String)VO. getCurrentRow (). getAttribute ("Company");

    String ProfitCenter = (String)VO. getCurrentRow (). getAttribute ()'ProfitCenter');

       String Dept = (String)VO. getCurrentRow (). getAttribute ("Dept");

       String Lob = (String)VO. getCurrentRow (). getAttribute ("Lob");

       String Account = (String)VO. getCurrentRow (). getAttribute ("Account");

    pageContext . putDialogMessage (new OAException()"inside loops'));

       if (null! = VO1 )

      { am. invokeMethod ("createRow");

    VO1 . getCurrentRow (). setAttribute ()'Description',Description);

      VO1 . getCurrentRow (). setAttribute ("Amount",Amount);

      VO1 . getCurrentRow (). setAttribute ("Company",Company);

      } ReqRow = (Row)VO.next(); }

       else {}

    }

    }

    Here is the method in AM.

    Public Sub createRow()
    {

    OAViewObject vo = (OAViewObject) getL3APCodingProjectEOVO1 ();

    vo.clearCache ();

    If (!) VO.isPreparedForExecution ())
    {
    System.out.println ("project VO executed");
    vo.setWhereClause (null);
    vo.setWhereClauseParams (null);
    vo.setWhereClause ("1 = 2");
    vo.executeQuery ();
    }
    Line = vo.createRow ();
    vo.insertRow (row);
    row.setNewRowState (Row.STATUS_INITIALIZED);

    }

    I modified your code a bit. This code does not require a method of AM.

    If the problem still not solved.

    If you want you can try this and let us know what happens.

    if (pageContext.isLovEvent())
    {
       String lovInputSourceId = pageContext.getLovInputSourceId();
       if("poNumber".equals(lovInputSourceId))
      {
      pageContext.putDialogMessage(new OAException("Inside Onclick"));
      OAViewObject VO=(OAViewObject)am.findViewObject("L3APNonprojbasedpoVO1");
      OAViewObject VO1=(OAViewObject)am.findViewObject("L3APCodingInfoEOVO1");
      VO.setWhereClause(null);
      VO.setWhereClauseParams(null);
      VO.executeQuery();
    
      VO1.setWhereClause(null);
      VO1.setWhereClauseParams(null);
      VO1.setWhereClause("1=2");
      VO1.executeQuery();
    
      if (VO != null)
      {
      for( Row ReqRow = (Row) VO.first();  ReqRow != null; ReqRow = (Row) VO.next())
      {
      String Description = (String)ReqRow.getAttribute("ItemDescription");
      Number Amount = (Number)ReqRow.getAttribute("Amount");
      String Company = (String)ReqRow.getAttribute("Company");
      String ProfitCenter = (String)ReqRow.getAttribute("ProfitCenter");
      String Dept = (String)ReqRow.getAttribute("Dept");
      String Lob = (String)ReqRow.getAttribute("Lob");
      String Account = (String)ReqRow.getAttribute("Account");
      pageContext.putDialogMessage(new OAException("Inside for Loop"));
    
      if (VO1 != null)
      {
      Row newRow  = VO1.createRow();
      newRow.setAttribute("Description",Description);
      newRow.setAttribute("Amount",Amount);
      newRow.setAttribute("Company",Company);
      VO1.insertRow(newRow);
      }
      }
      }
      }
    }
    

    See you soon

    AJ

Maybe you are looking for

  • Are there any known problems with external battery for iPhone 6 s karim?

    Are there any known problems with external battery for iPhone 6 s karim? Jackery of input: 5V / 2. 1a. I had heard that some may damage internal parts of the phone. I am interested in what Apple says rather than what says karim. Thank you.

  • 630 HP: HP630: graphic driver problem

    Hello I get the following message appears when I try to install the graphics driver for your laptop HP 630: this computer does not meet the minimum requirements I downloaded the drivers on the download page. Unfortunately due to the age of the laptop

  • Re: Need new drive for Satelloite A40-702

    Hiya, My friend has an old Toshiba A40-702 and the 40 GB IDE hard drive died. The smaller new IDE hard drive I can buy here where I live is 160 GB, anyone know if the laptop will recognize a hard drive of this size? I searched on the web and the Tosh

  • Satellite P10-804 - bad sound

    SP10 804 Windows xp pro., I have very bad its mediaplayer throughexternal amp, but my other program PCDJ plays very well, all my friends colin ideas,

  • Wrong time file Express with NI9361 medium Freq dynamics of the signal

    I have an interesting problem with recoding of the frequency to a file with SignalExpress measures and a NI9361. I was able to find a workaround, but here's the question: As in the attached SignalExpress project, I'm analog acquisition of voltage usi