Conversion 'numbers' consecutive beaches

I would like to comment on an algorithm that identifies the strings in a list of "numbers." Any comments will be appreciated.

I have a series of strings indicating the numbers of section like this:

102.2, 102.3, 102.4, 102.5, 102.6, 102.16, 102.17, 102,18, 102.19

What I want to do, it is the collapse of three or more consecutive numbers in the ranges:

102.2 - 102, 6, 102.16 - 102.19

First of all, I convert the string to an array of numbers of sections. Then I get two lists of numbers; one of the hundreds, the other with dozens. Then, I go through these lists, identify the ranges and return a list of positions in the table. Also, in this example, I get:

1

5

6

9

If the length of the positions is less than the table, I know there is at least a beach. Now, I am going through the ranges to understand that members eliminate table. I'm starting at the end of the list of positions and subtract [x] - [x-1]. Then

9 - 6 = 3

6 - 5 = 1

5 - 1 = 4

Any result > 1 is a range. I subtracted 1 from the result and which tells me how many members to eliminate the table. So for the first, I delete two members after the 6, 7 and 8. I jump the other because the result is not greater than 1. The third argument gives me 4-1, so I remove 3 members after position 1 (2, 3, 4). The table ends up with 102,2, 102.6, 102.16 102.19.

Note that the way I have the hyphens in the correct position is not important here. Also, my descriptions of the above posts assume 1 as the first position, not 0 as they are in JavaScript arrays.

Here is my code in JavaScript. Any suggestions for simplification of the algorithm are appreciated. Thank you.

Rick Quatro

var refs = "102.2, 102.3, 102.4, 102.5, 102.6, 102.16, 102.17, 102.18, 102.19"; 
// Convert the string into an array.
var refsArray = refs.split(", ");
// Split the numbers into hundreds and tens places.
var numbers = getNumberSets (refsArray); 
// Return a list of positions in the array, indicating ranges.
var positions = getRangePositions (numbers); 
// Delete the unneeded members from the refsArray.
removeRedundantMembers (positions, refsArray); alert (refsArray);

function removeRedundantMembers (positions, refsArray) {

    var count = positions.length - 1, span = 0;
    // Loop from the end of the array to the beginning
    for (var i = count; i > 0; i -= 1) {
        // Get the distance between to consecutive positions.
        span = positions[i] - positions[i-1];
        if (span > 1) {
             // Remove the unneeded members.
             refsArray.splice(positions[i-1] + 1, span - 1);
        }
    }
}

function getRangePositions (numbers) {

    // Make an array of positions.
    var positions = [];
    // Make variables to store the current hundreds and tens values.
    var hundred = -99, ten = -99;

    for (var i = 0, count = numbers.hundreds.length; i < count; i += 1) {
        if (numbers.hundreds[i] !== hundred) {
            // hundreds value changed; store this position.
            positions.push (i);
            // Update current hundreds and tens values.
            hundred = numbers.hundreds[i];
            ten = numbers.tens[i];
        } else {
            // hundreds stayed the same; check tens place.
            if (numbers.tens[i] !== (ten + 1)) {
                // More than one tens places skipped; store this position and the previous.
                positions.push (i-1);
                positions.push (i);
            }
            ten = numbers.tens[i];
        }
    }
    // The last position is always needed.
    positions.push (count-1);
    return positions;
}

function getNumberSets (refsArray) {

    // Make an object of arrays for the number parts.
    var numbers = {hundreds: [], tens: []};
    // Make a regular expression to split each number.
    var regex = /^(\d+)\.(\d+)$/, match;

    // Loop through the references and split each one at the dot.
    for (var i = 0, count = refsArray.length; i < count; i += 1) {
        if (regex.test (refsArray[i])) {
            match = regex.exec (refsArray[i]);
            // Convert the individual strings to integers and add them to the arrays.
           numbers.hundreds.push (parseInt(match[1], 10));
           numbers.tens.push (parseInt(match[2], 10));
        } else {
            // Regex doesn't match, so add zeros to the arrays.
           numbers.hundreds.push (0);
           numbers.tens.push (0);
        }
    }
    return numbers;
}

I think I got it.

You get in trouble because you can have either a digit after the full stop, or two (or maybe more). The trick, then, not to treat it as a number decimal as a fraction, but as two distinct numbers.

When comparing two numbers, as long as the first number in the first is not the same as the first number in the second set, jumping. Then, count same-prime-number croissants values for the second number. That if this set is greater than 2 long count, issued the first number and the last with a hyphen in between. For all other cases, issue starts just the original number and a comma followed by a space.

In the code:

itemlist = app.selection[0].contents;

separated = itemlist.split(', ');
for (i=0; i 2)
          {
                    result += '-'+separated[j-1][0]+'.'+separated[j-1][1];
                    i = j;
          } else
          {
                    result += ', '+separated[i][0]+'.'+separated[i][1];
                    i++;
          }
}

alert (result);

Tags: InDesign

Similar Questions

  • are consecutively numbered table of contents and headlines

    Hello Adobe community.

    I have two questions about RoboHelp HTML (RoboHelp 9).

    1st issue)

    It is possible titles are numbered consecutively as in this example (a lower heading level always has the number on the upper level in front of it.):

    1. Title ABC
    2. Headline DEF

    2.1 title YES

    2.2 title POI

    2.2.1 title ZUI

    3. the title XYZ

    The example is as a numbering system is possible in microsoft word.

    And the important thing is that the titles are linked to another in a way that fade "2. Headline DEF"2.1, 2.2, 2.2.1 becomes 1.1, 1.2, 1.2.1.

    2nd question)

    Is it possible, the table of contents consecutively regardless of the books, pages and bookmarks of numbering?

    Example:

    1. Book 1

    1.1 page 1

    1.2 page 2

    1.2.1 Bookmarked_Headline 1

    1.2.2 Bookmarked_Headline 2

    1.3 page 3

    1.4 Bookmarked_Headline 3

    The numbers that are used in the table of contents must be the same as titles on the pages there.

    I hope you understand my English and can help me.

    Kind regards

    Denis

    What you use in the topics is a multilevel list. See my site for more information on the use of lists.

    They may not apply to the content of the table of contents, and now there's a way around what I know, other than manually numbering the books and topics.

    Many people move away from the numbering otherwise than in specialized areas.

    See www.grainge.org for creating tips and RoboHelp

    @petergrainge

  • HELP: Consecutive Multiples of numbering per Page - multiple Pages

    I work with a document, InDesign 8.5 "x 11" which has eight 4.25 "x 2.75" "coupons" per page - see the example below.

    All coupons must be numbered consecutively and automatically 00001-00008 on page 1, 00009-00016, on page 2, etc. before printing and cutting in eight individual coupons. I know I can do it manually, but I'd rather not because it can eventually be dozens of pages.

    My questions...

    -Is it possible?

    -If Yes, how can it be done using InDesign?

    I appreciate any help!

    BNB_Coupon.jpg

    I created a grid in Excel with numbers running down the columns, each column representing a stack after the cut. The grid needs the number of columns equal to the number of tickets or coupons or another on each sheet, and the number of lines equal the number of sheets needed to produce the total.

    Add a header with the names of the fields row stack, stack two, etc., and then export to .csv and use merge data with a one-record by the layout. It has been explained several times now...

  • I can restart list numbering on a new page?

    It seems like it should be simple, but I can't understand it. I want that my lists numbered in text frames linked to automatically restart on a new page. It is a book of exercises, and on each page should restart at the 1. Can I do this without unwire my text boxes?

    Okie doke, I understood how do. All styles have already been assigned in this book, so I wanted to avoid the addition of a new style, and then manually change the style of paragraph for the first element in hundreds of pages. Instead, I can just change the definition of the styles. I post here in case anyone is looking for the same concept.

    Rather than restart the number on each page, what I was really trying to do was start numbering at 1 for lists numbered following a specific head, the title of this series of exercises, which is also numbered consecutively by the document. The key is to use levels of lists. This is my first style, head:

    And here is my second style, the numbered list:

    TADA! Thanks to those who took the time to post.

  • Conversion of Word 2007 in Adobe Reader documents

    Anyone with problems of conversion numbers Word in Adobe Reader 9? Once converted to Adobe Reader the object disappears.  All other pictures/characters appear without problem.

    Adobe Reader cannot convert Word documents.

  • Line numbers in the table in a calculated text field

    How calculated script works incrementally number a field calculated and return the number of lines in the field of the extreme left of a table?

    What I need, is that each row in the table is numbered consecutively in the area of the far left and that the new created lines are numbered correctly at the end of the user.

    Hello

    You have to move the script to the layout event: loan. This isn't the most effective event, because it triggers every time changes. For this reason however your needs well, because whenever a row is added or deleted, the index numbers will be updated.

    Here is an example letter (for a maximum of four lines). The same approach should apply to numbers. The script is located in the layout event: loan of the first cell.

    There is an example here: https://acrobat.com/#d=Zk2XWWDUWNfG * VuRTNy5QQ

    Good luck

    Niall

  • with the master page "insert current page number" error when you export the book

    Using InDesign CS for Windows 5.5

    Recently updated for InDesign CS (very old one from 2003). I save a copy of all my old files version and kept the old installed ID just in case (after reading all the horror stories on here).

    In my old version of ID, I created a book consisting of some 70 documents. Some of these documents are a single page, while others have multiple pages. In the multiple documents page, I used the "insert... current page number" character (or whatever the command was in the old version) on a page master and formatted as follows, for example: Page 1 of 17, Page 2 of 17, Page 3 of 17, etc. When I exported my book in pdf format, it worked fine. (I is not have to / want page numbers consecutive throughout the book, only in individual documents.) By that I mean my whole book is about 280 pages, but not all of these 280 pages are numbered, only groups of pages in multi-page documents. It is not read page 1-280).

    Am my upgrade to 5.5 a few months ago added some documents in the book, and (if I remember correctly) when I saved the book he asked to convert each document version to the new version, I said OK. When I exported the book in pdf format, some documents that are more than 2 pages are now counted wrong; the numbers are now like this: Page 1 of 17, Page 2 of 17, Page 2 of 17 (supposed to be page 3), Page 2 of 17 (supposed to be page 4), etc. Each page, but page 1 is now page 2 of that either.

    If I open the individual document and export it to PDF, the page numbers work very well. It is only when the document is exported with the book the page numbers to spoil. And it's not all documents in my book; This error starts to a particular document and continues from there throughout the rest of the book, affecting any document more than 2 pages. Documents several pages before that point in the book for export with the correct page numbers.

    I create new documents by performing a "save under" with a previously created document and cut and paste as needed, so I won't have to reformat or implement the page numbers on each new document. I use layers or styles (I do not know there is a better way to do what I need, but I didn't have time to learn the basics, just enough to be functional.)

    My attempts to resolve this problem so far (using version 5.5), tests with the first document where the error: (1) I have removed the document from the book, removed the page number character current insert, back to the current page number character insert, saved, the individual document exported in pdf format and it worked fine. Put it in the book, save, export, and it is bad. (2) I picked up the book document, export the document to .idml, registered as a new .indd new name, exported to PDF and it worked fine. Put it in the book, save, export, and it is bad. (3) I started to the top of my old version of ID, open from the previous version of this document, exported .inx, closed, open the .inx in ID 5.5, registered as a new .indd new name, exported to PDF and it worked fine. Put it in the book, save, export, and it is bad. (4) I moved the document to the top in the order book, put it on a document which correctly numbered pages, saved, exported to PDF and this document was still evil, but one who has been numbered correctly all along is still correct. (5) I compared the settings for this document to others that the number properly and found no difference.

    It's as if the page numbers get hooked on "2" when I export the book, but only in the last two-thirds of the book. Sorry this is so long, but I hope that this description of my problem is understandable. Any advice, other than to go back to my old version documents and start over?

    Thank you for your time and all the information great this forum provides.

    Alice

    Normally, I would say that this kind of problem is symptomatic of the incorrect numbering options in the book panel or an individual document or a bad update of the numbering, and those things are still definitely worth looking at.

    That said, I invite you to go to the original files, export each one to .inx and open those in CS5.5 and save as a new file .indd CS5.5 whose new name, then add them to a whole new book CS5.5. Books are pretty flakey without mixture in the conversion of files, and there are enough bad behvior file conversion directly inherited the .inx route is insurance a little success.

  • WMP11 - using letters in the track number column

    I realize that the name of the column gives a bit average, but I have a few tracks that have numbers of beach named originally by the artist as A1, A2, B2...

    If I name them this way WMP11 removes the letter and displays tracks 1 set and then 2 tracks together, IE in the wrong order.
    Is that from a distance I can get WMP to see the letters?
    I realize that the easy solution would be to rename them but 1,2,3,4,5,6 Hey would love to find an elegant solution
    Also can help someone else out there :-)
    Thanks for your help

    Hello

    Here are a few links were you can post this question for best results:
    http://experts.Windows.com/FRMS/default.aspx

    https://connect.Microsoft.com/
    hope this helps,
    Eddie B.

  • GETVPN

    Make a few tests before direct implementation, have a small network of laboratory of GETVPN, unique KS, 5 GMs to 12.4 (15) T10.  All encryption, routing, etc. works very well except something odd I noticed.

    Of key server;

    C2851_Key_Srvr #sh gd ks cry me

    Member of group information:

    Number of new generated key sent to group GETVPN: 170

    Group Member ID: 172.16.1.1

    Group ID: 1234

    Group name: GETVPN

    Key server ID: 172.16.0.1

    New generated keys sent: 170

    Redials attempts: 0

    Recomposition of receipts Rcvd: 170

    Generate a new key missed Acks: 0

    Envoy seq num: 2 1 0 0

    RCVD seq num: 2 1 0 0

    ......

    ......

    Member of the Group:

    * 09:34:43.574 May 17: % GDOI-5-GM_RECV_REKEY: receipt given to the key for the Group PGroupfrom 172.16.0.1 to 172.16.4.1 with seq # 1

    * 09:55:33.701 May 17: % GDOI-5-GM_RECV_REKEY: receipt given to the key for the Group PGroupfrom 172.16.0.1 to 172.16.4.1 with seq # 2

    * 11:20:39.221 May 17: % GDOI-5-GM_RECV_REKEY: receipt given to the key for the Group PGroupfrom 172.16.0.1 to 172.16.4.1 with seq # 1

    * 11:55:34.433 May 17: % GDOI-5-GM_RECV_REKEY: receipt given to the key for the Group PGroupfrom 172.16.0.1 to 172.16.4.1 with seq # 2

    * 13:06:34.865 May 17: % GDOI-5-GM_RECV_REKEY: receipt given to the key for the Group PGroupfrom 172.16.0.1 to 172.16.4.1 with seq # 1

    * 13:55:35.164 may 17: % GDOI-5-GM_RECV_REKEY: receipt given to the key for the Group PGroupfrom 172.16.0.1 to 172.16.4.1 with seq # 2

    ... the sent sequence numbers & rcvd will never more than 2.  In fact, they repeat the model: 1,2,1,2,1, 2... forever.

    It is a behavior as the Guide design and implementation &, section: 5.3.3.2 says:

    .......

    .......

    If all the GMs in the response of the Group GET VPN do on a generation of new unicast key, generate a new key syslog messages are displayed with incrementing sequence numbers consecutive.<>

    .......

    .......

    If syslog does not display numbers in sequence to generate a new key increment properly (last sequence number + 1), which indicates that the primary KS sends certain retransmissions to generate a new key because receipts of some GMs is not received.

    This implies, seq #s should increase 1,2,3,4,5...

    Anyone shed some light on this issue? Is this a real problem or not?

    much appreciated!

    DJS

    In the "sh gd ks me cry ' output you sent, it seems that the KS 170 generate a new key messages sent and received all generate a new 170 key ACKS. On this basis, nothing seems wrong. You might see the repetition because a generation of new KEK resets the sequence number 1. A generation of new KEK is when a new KEK is generated and TEKS of new possible according to their life expectancy. All consecutive TEK new generated key increment from there. Examine your lives to KEK and TEK, but based on the syslog horodateurs Im guessing this is probably the explanation.

    Just to be on the safe side, I'll keep an eye on your GMs in your test environment and monitor to see one or more trying to re - save when IPSec security associations are on expire (about 60 seconds) because this would indicate a problem with the front desk is not the new generated key.

  • How to check that an announcement printed in the magazine - Workflow

    Hello!

    Without knowing about the publication, asked me to create and submit ads with my digital photos (and text on them), to high-end magazines.

    So far I have no complaints after a year to do, but there are things that I want to be able to do and do not know how.

    For example, to check that the final announcement has fillings or the best dynamic range possible for CMYK.

    It seems that after exporting the PDF from Indesign, I can rate it on acrobat (preflight?), which seems to be a good workflow.

    I couldn't find, however, a lot of documentation on the whole process of preparation of a photo to be printed (photoshop and Indesign), dealing with the ICCS, CMYK, standard magazines, preparation of the PDF file and finally evaluate the PDF file with the "print production tools.

    In fact, I found a lot of conflicting information.

    Does anyone know a great book or resources on the complete workflow of place once loved photos in Indesign, all the way to analyze a ready CMYK PDF (the proofing or preflight, not sure what the difference between) in acrobat pro?

    FYI: I save the file with ICC (sRGB) in Photoshop and performing the conversion to CMYK in Indesign when you export to PDF, no CCI format.

    Thank you!

    As for TAC, what happens if it shows that you are above the limit. How do fix you this?

    The total ink limit is integrated in the profile, which is another reason, you want to have the right profile to your document if you export to X - 1.

    The gray and black balance amount of generation is also integrated in the profile, so in Photoshop, if you set the workspace CMYK in the color on the destination profile settings, you can keep the image in RGB mode and see the exported values when you set the Panel Info to CMYK. If there is too much magenta in black and looking for neutral, chances are that your RGB values are not even.

    I have a gray fill AdobeRGB in Photoshop with GRAcol defined as CMYK for Info workspace displays the conversion numbers. In InDesign GRAcol is assigned CMYK profile if I get consistent numbers in MS for the placed image preview. And when I saw the export of PDF/X-1 of the output gives me the same numbers, but the object is now CMYK not RGB.

  • CS6 renfilez / reconnection story that I have not threaded - reference problem

    This started as a reference problem. My notes are not always numbered consecutively. I searched the forum and found many complaints about the notes. I think that my problem is that the CS6 begins renumbering of notes if it detects a new "history". I voluntarily started my chapter 28 pages with a full story. However, somewhere along the line, the thread of the story broke. I did a lot of formatting with graphics and images before noticing the notes were again starting with the number 1. I want to join the pieces of the story. How can I do?


    Marsha using Mac Yosemite

    I found the answer after looking everywhere for it!

    Nigel French lesson illustrates and explains how to join two text blocks Threading text InDesign CC EPUB typography | Lynda.com

    OPTION-click on (or ALT-click) the outport of the last frame of the first story then click on as part of the second image to join into one.

  • How to make the notes?

    Hi all

    I found the below instructions for making the endnotes, but met with some difficulties and would really appreciate your advice.

    Create an endnote

    1. Type the first note at the end of the document and assign it the paragraph to endnotes format. The paragraph format should include an AutoNumber so that notes will be numbered consecutively.
      Jessie: I did this - I created Endnote1 (the first issue of a numbered list endnote) paragraph formats and Endnote (second + elements in a numbered footnote list). I typed my two notes at the end of the document and applied formats and they number correctly.
    2. Click where you want to insert a reference to footnote and the reference to the footnote end use the cross-reference format that you created for the endnotes.

      For example, if the endnote references must be posted by exhibiting, and if the document contains a character exponent format, the format of cross reference < Exhibitor > < $paranumonly > displays the paragraph AutoNumber notes superscript.
      [Jessie: this is where I struggle, and I do not fully understand these instructions.] I typed a '1' for my first grade where it should be. I have pointed out and created a character exponent format. Then, I want to cross this supercript 1 to my paragraph Endnote1 format, which is the first item in my list of endnote. I pointed out the Exhibitor 1 and go to the cross-reference panel.

      Once I'm in the cross-reference Panel, I select "Endnote1" and click on the corresponding text that appears to the right. THEN, I go down to the reference Format drop-down list /, where I'm supposed to chose the format of the cross-reference. As none of those here apply (chapter number, section number, etc.), I clicked on change Format. I appointed a new "EndnoteReference"... but I don't know what to do in the definition box. I don't know what building blocks, I am supposed to use, etc.

    Anyone who can explain to me how by mere reference grade Exhibitor the text of the actual mark at the end of the document will help me go to this to this

    Thank you in advance!

    Jessie

    The "" represents the character tag used for the superscript. It looks like yours is either spelled or named differently, so change the cross-reference format to use that one.

  • Batch rename multiple files without zeros (0065) and 1, 2, 2 (2)

    Hello

    When you rename say 100 images, you can select three numbers and create something like:

    Image _001

    Image _002

    Image _003

    Image _004

    Image _005

    ...

    Image _067

    Image _068

    Image _069

    and so on.

    But if you select a number that comes out as:

    _1 image

    _2 image

    _3 image

    _4 image

    _5 image

    _6 image

    _______________7 image

    Image _8

    Image _9

    Image _1 (1)

    Image _2 (1)

    _3 image (1)

    Image _4 (1)

    _5 image (1)

    _6 image (1)

    _______________7 image (1)

    _8 image (1)

    _9 image (1)

    _1 image (2)

    Image _2 (2)

    _3 image (2)

    Image _4 (2)

    Can bridge rename to say 1 to 100 without the zeros, yet still numbering consecutively without (#)?

    I'm looking:

    _1 image

    _2 image

    _3 image

    _4 image

    _5 image

    _6 image

    _______________7 image

    Image _8

    Image _9

    _10 image

    _11 image

    _12 image

    ....

    Image _97

    Image _98

    _99 image

    _100 image

    _101 image

    Seems simple enough.

    Hello

    I have a "Preset" that does what you are looking for...

    In renaming the lot, I use a possibility of substitution of string with a regular expression "_0" _00"- which means"find OR _00 _0. "

    New file names

    • Substitution string - Original - Find _0 file name | _00 - replace with _

    (Make sure 'Ordinary use of the Expression' is checked)

    See screenshots below...

    Kind regards...

  • How to add a counter to repeated dynamic subforms

    Hello

    I have created a form that has a dynamic form interactive void.

    I want sub forms were soon, that is to say the first is 1, second - 2 and every time a user adds or removes an instance, sub forms are numbered consecutively.

    How can I do this?

    Thanks in advance for your answers.

    Here is a sample file for you...

    https://Acrobat.com/#d=gAGLpR7ETsBvowyLBIzcMA

    I placed the code in the event LayOut Ready of the TextField to display the subform repeating below index...

    this.rawValue = this.parent.index;

    And in the Click event of the button Instance remove:

    Subform1.instanceManager.removeInstance (this.parent.index);

    XFA. Form.Recalculate (0); Passing 1 as this method works.

    I hope this helps.

    Thank you

    Srini

  • How to compare consecutive groups of numbers in tables

    Hello

    I need from there to place a table 1 d of the solution.

    I need to compare two tables and record the same numbers that are in the two tables, but also save groups of numbers which can be in one of the two compared tables.

    In the example l could not put all consecutive numbers 8,9,10,11,12 groups in a 1 d array.

    Example l have to filter the zeros and the number four.

    The numbers in the two tables are always in descending order however may not be in the order of the array index number. It's 15 = 15 index number

    A series of consecutive numbers in this example is a group which increase by a value of 1. For example. 8,9,0,22,23,24 are two consecutive groups of numbers.

    Thank you


Maybe you are looking for