Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. ttomasko

    How to delete all duplicates in an array

    I would be interested in seeing the code for such a comparison. However in this case I'm not sure it it necessary. In InDesign I will be comparing a list of paragraph styles from each of two documents. In most cases the two lists will be exactly the same. But sometimes someone adds some styles...
  2. ttomasko

    How to delete all duplicates in an array

    Thanks very much! I knew I was on the right track but took a wrong fork in the road. I will be comparing two lists of strings. They will be concatenated and then sorted. I am looking for whatever might have been added to the second list. It would not be possible that there would be triplicates...
  3. ttomasko

    How to delete all duplicates in an array

    var a = [1,1,2,2,3,4,4,5,6,6]; for(var i = 0; i <a.length-1; i++){ if(a[i] == a[i+1]){ a.splice(a[i],2); }//end if }//end for i alert(a);
  4. ttomasko

    How to delete all duplicates in an array

    Hello, I have an array: var a = [1,1,2,2,3,4,4,5,6,6]; I need to delete all the duplicates, i.e., both pairs of each duplicate so that I am only left with the elements that are unique. In the example above the result should be 3, 5. I've tried pushing or splicing to no avail. Any...
  5. ttomasko

    How to preserve values in a multiple iteration

    Thanks Phil! Now to stick this in to the much more complicated script... Tom
  6. ttomasko

    How to preserve values in a multiple iteration

    Hello, I have a script that has three levels of for statements. Right now the end result is that I get returned the last values of each array. What I wish however is to preserve the values of the first and second iterations. var a = [1,2,3]; var b = ["a","b"]; var c = ["x","y","z"]; for(var i...
  7. ttomasko

    Finding the difference between two arrays

    Feherke, No, you did not challenge my patience. This is how to learn. You are right that the coding I used will sometimes fail. The missing 2 in this case has an index other than -1 so it doesn't get pushed to the new array. Your code fits the bill and is a lot simplier. I tried it with...
  8. ttomasko

    Finding the difference between two arrays

    Feherke, I tested out [1,33,4] against [1]. The difference array is [33,4]. I tried other permutations and always get what I am looking for. Maybe I did not make clear in my first note that opened this discussion that of the two arrays, the smaller one is always a subset of the other. The...
  9. ttomasko

    Finding the difference between two arrays

    Feherke, You didn't catch what I said. I am not working in a browser. I am applying JavaScript to an Adobe product. Further, the indexOf method does not work on arrays in InDesign, at least not the CS3 version. So I have to turn one of the arrays into a string, the one I will apply the indexOf...
  10. ttomasko

    Finding the difference between two arrays

    Feherke, You didn't catch what I said. I am not working in a browser. I am applying JavaScript to an Adobe product. Further, the indexOf method does not work on arrays in InDesign, at least not the CS3 version. So I have to turn one of the arrays into a string, the one I will be apply the...
  11. ttomasko

    Finding the difference between two arrays

    Whoops! There is a big bug in the ointment: Numbers larger than one digit. IndexOf looks at a number such as 20 and sees values of 2 and 0. Sigh...too late at night to solve now. Tom
  12. ttomasko

    Finding the difference between two arrays

    OK, I have solved it. Thanks Phil for the idea of using indexOf(). There is a problem however with using this method in the InDesign object model; it does not recognize its use with numbers, only strings. So below I turn the two arrays of numbers into strings. I then iterate thru the major...
  13. ttomasko

    Finding the difference between two arrays

    Dear Dan and Phil, I'll work on this and report back. But things have intervened and it will take me a few days. Tom
  14. ttomasko

    Finding the difference between two arrays

    Dan, They are similar problems, and posing the three I did in the past (one very recently) has helped me solve those problems. They are probably similar because I am applying JavaScript to the InDesign object model. Almost all the objects are found in arrays. I am writing scripts that will...
  15. ttomasko

    Finding the difference between two arrays

    Hello, I will have two arrays of numbers. One will always be a subset of the other. What I want to know is which numbers only appear in the major set and put them in an array: var a = [1,2,3,4,5,6]; var b = [1,2,3,6]; //result I want: [4,5] I have tried concatenating a and b and then looking...
  16. ttomasko

    How to delete all duplicates in two arrays

    Dan, I'm still not sure what you are getting at. You seem to say I do not have to iterate thru the array. However, in the meantime I have solved it: var a = [11,12,13,15,16, 19,20]; var c = []; var gapArr = []; for(var i =0; a.length > i; i++){ if(a[i] + 1 < a[i+1]){ var gapLength = a[i+1]...
  17. ttomasko

    How to delete all duplicates in two arrays

    Dan, Your advice helps, though I did not completely understand it. The following finds any gaps but returns only the first missing number where there are more than one missing numbers. var a = [11,12,13,15,16,19,20]; var c = []; for(var i =0; a.length > i; i++){ if(a[i] + 1 < a[i+1]){ var b...
  18. ttomasko

    How to delete all duplicates in two arrays

    Hello, I have been tearing my hair out on how to solve this. I will have an array of numbers. I'll never know the starting and ending numbers but they will be in order. However, there may be gaps in the order. It is the gaps I am interested in. Let's say I start with the following array: var...
  19. ttomasko

    How to cut short an alert that is way too long

    Kendel, No, making more than one alert would be unmanageable. This script is simplified and non-InDesign Object Model. The more complex version will look for certain types of errors in, say, a 100-page document. Sometimes there are just a few errors and it is no biggie to just have an alert...
  20. ttomasko

    Question about switch statement

    Hello, Is it possible to use the switch statement with inequalities? For instance, the following does not work. Tom var x = 4; switch(x){ case <5: alert("do something"); break; case 5: alert("do something more"); break; case >5: alert("do something really big"); break...

Part and Inventory Search

Back
Top