> > I'd like to use enumeration functions to select from a sorted list
> > where I know that if the select function has passed and then starts
> > failing (returns false)

This isn't a prime situation for Enumerable but certainly nothing it
can't handle.

> Never mind - I just discovered $break in the docs

Really, what documentation covered the $break variable?  I've always
considered this as Prototype property and although you can get away
with it in most cases, I'd strongly advise against manipulating that
variable yourself.

I'm not sure what use case you're going for, are you collecting the
items in the array that match or just getting to the max index of
matches and then exiting?

Here is some quick and dirty code of how to work out a situation like
yours with Enumerable methods...

var vocab = [
                                "apples",
                                "apricot",
                                "airplane",
                                "bass",
                                "banana",
                                "bounce",
                                "card",
                                "carry",
                                "cart",
                                "ceasar"
                        ];

var myFlag = false;
var myRegex = /^b.*/;

var myFilter = function(val, itr){
        if(val.search(myRegex) > -1 && myFlag == false){
                myFlag = true;
        }
        else if(val.search(myRegex) == -1 && myFlag == true){
                myFlag = false;
        }

        return (myFlag && val.search(myRegex) > -1);
}

var newVocab = vocab.collect(myFilter);

console.log(newVocab);




On Nov 9, 6:47 am, "andy.kri...@gmail.com" <andy.kri...@gmail.com>
wrote:
> Never mind - I just discovered $break in the docs - that should do
> what I want.
>
> On Nov 9, 6:41 am, "andy.kri...@gmail.com" <andy.kri...@gmail.com>
> wrote:
>
> > I'd like to use enumeration functions to select from a sorted list
> > where I know that if the select function has passed and then starts
> > failing (returns false), I can stop enumerating (because every
> > additional item will also fail). For example, scanning a sorted array
> > of strings for strings that start with a regexp - once the regexp has
> > found matches and then stops matching again, there's no need to
> > continue.
>
> > Is that possible with the built-in functions or should I be looping
> > over the array myself in this case?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to