liorean
11-27-2003, 10:33 PM
Okay, I have a challenge for you other JavaScript gurus out there. There's no price except the prestige of having beaten the rest of us, but anyway, I hope as many as possible find it a challenge worthy of entering their own contribution to.
The challenge:
An array processing function or method that has the following characteristica:
- It allows processing of the array members in forward (default) or reverse order. (Additionally, random order is optional, but would add a point or two in my books.)
- It allows exclusion of members based on a condition supplied to them in the form of a function literal returning a boolean value.
- It allows for multi-element reading frames in the following manner:
* Array to process: [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l' ]
* Reading frame: 3 elements
* Frame span: inclusive
(The other possibility, exclusive, would mean that there is no overlap between frames. How to solve cases where this means the last set of elements would not be enough for an entire reading frame is up to you.)
* Exclusion: element equal to 'd' or 'f'
* Processing: [ ['a', 'b', 'c'], ['b', 'c', 'e'], ['c', 'e', 'g'] ... ['j', 'k', 'l'] ]
- It allows for the possibility of deep processing of nested arrays (only for cases where the reading frame is a single element)
- It allows for cascaded processing in some way
- The processing to take place is supplied by a single function literal or reference
Everything else is up to you. Let's see what you have got!
(I'll throw in an entry of my own take on this later on, so that my entry won't influence you too much.)
The challenge:
An array processing function or method that has the following characteristica:
- It allows processing of the array members in forward (default) or reverse order. (Additionally, random order is optional, but would add a point or two in my books.)
- It allows exclusion of members based on a condition supplied to them in the form of a function literal returning a boolean value.
- It allows for multi-element reading frames in the following manner:
* Array to process: [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l' ]
* Reading frame: 3 elements
* Frame span: inclusive
(The other possibility, exclusive, would mean that there is no overlap between frames. How to solve cases where this means the last set of elements would not be enough for an entire reading frame is up to you.)
* Exclusion: element equal to 'd' or 'f'
* Processing: [ ['a', 'b', 'c'], ['b', 'c', 'e'], ['c', 'e', 'g'] ... ['j', 'k', 'l'] ]
- It allows for the possibility of deep processing of nested arrays (only for cases where the reading frame is a single element)
- It allows for cascaded processing in some way
- The processing to take place is supplied by a single function literal or reference
Everything else is up to you. Let's see what you have got!
(I'll throw in an entry of my own take on this later on, so that my entry won't influence you too much.)