Indiscripts

Tag : Algorithms

On Dichotomic Divide-and-Conquer Algorithms

From what I observed, InDesign scripters do not naturally resort to the dichotomic (or binary) search algorithm when it comes to find a numeric solution to problems as wide as adjusting frame bounds to some constraint, determining an optimal text size, or simply accessing a needle in the haystack. Yet the binary search approach is nearly always the best. So let's make it more popular…

Continue reading...

Reconsidering Array.sort( ) in ExtendScript/JavaScript — Part 2

In my previous post I introduced some key concepts and tools for benchmarking Array.sort() and took you through the “standard model” of optimizing the callback function. We also emphasized that, of course, it is impossible to go faster than the native method. If these clues made you sit up and take notice, it's time to go one step further…

Continue reading...

Reconsidering Array.sort( ) in ExtendScript/JavaScript — Part 1

The pattern array.sort(compareFunc) is widely used by JavaScript programmers when elements being sorted are not supposed to represent basic strings in the sense of UTF16 ordered character sequences. In particular, sorting numbers forces you to provide that stupid custom compareNumbers routine which, in most cases, just looks like function(x,y){return x-y}. And even when you have to sort actual strings, there are countless situations where the default Unicode code point order is inappropriate. But a question arises: what is the performance cost of using a non-native comparison routine?

Continue reading...

Page Range Formatter

Given an unordered set of page numbers—e.g. {13, 9, 25, 12, 11, 8}—we often have to compute and output a range specification in the form "8-9; 11-13; 25". While this topic has been already discussed in the InDesign scripting forum, I'd like to explore today a slightly different approach…

Continue reading...