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...
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...
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...
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...
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...
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...
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...
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...
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
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...
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...
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...
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]...
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...
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...
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...
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...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.