src/arraydb.js
function query( q, limit, offset ) {

        var i, _l, res,

            strict  = true,
            reverse = false;

        if ( this.length === 0 || arguments.length === 0 ) {

            return [];

        }

        if ( typeof q === 'object' && q != null
            && 'query' in q
            && arguments.length === 1 ) {

            limit   = +q.limit;
            offset  = +q.offset;
            strict  = !!q.strict;
            reverse = !!q.reverse;
            q       = q.query;

        }

        if ( isNaN( limit ) ) {

            limit = Infinity;

        }

        offset = offset || 0;

        if ( typeof Array.prototype.filter === 'function' ) {

            return this.filter(function( o ) {

                return match( o, q, strict ) === !reverse;

            }).slice( offset, offset + limit );

        }

        res = [];
        _l  = Math.min( this.length, limit + offset );
        i   = 0;

        for ( ; i<_l; i++ ) {

            if ( match( this[ i ], q, strict ) === !reverse ) {

                if ( offset-- > 0 ) { continue; }

                res.push( this[ i ] );

            }

        }

        return res;

    }
function query( q, limit, offset ) {

        var i, _l, res,

            strict  = true,
            reverse = false;

        if ( this.length === 0 || arguments.length === 0 ) {

            return [];

        }

        if ( typeof q === 'object' && q != null
            && 'query' in q
            && arguments.length === 1 ) {

            limit   = +q.limit;
            offset  = +q.offset;
            strict  = !!q.strict;
            reverse = !!q.reverse;
            q       = q.query;

        }

        if ( isNaN( limit ) ) {

            limit = Infinity;

        }

        offset = offset || 0;

        if ( typeof Array.prototype.filter === 'function' ) {

            return this.filter(function( o ) {

                return match( o, q, strict ) === !reverse;

            }).slice( offset, offset + limit );

        }

        res = [];
        _l  = Math.min( this.length, limit + offset );
        i   = 0;

        for ( ; i<_l; i++ ) {

            if ( match( this[ i ], q, strict ) === !reverse ) {

                if ( offset-- > 0 ) { continue; }

                res.push( this[ i ] );

            }

        }

        return res;

    }
function query ( q , limit , offset ) { var i , _l , res , strict = true , reverse = false ; if ( this . length === 0 || arguments . length === 0 ) { return [ ] ; } if ( typeof q === 'object' && q != null && 'query' in q && arguments . length === 1 ) { limit = + q . limit ; offset = + q . offset ; strict = ! ! q . strict ; reverse = ! ! q . reverse ; q = q . query ; } if ( isNaN ( limit ) ) { limit = Infinity ; } offset = offset || 0 ; if ( typeof Array . prototype . filter === 'function' ) { return this . filter ( function ( o ) { return match ( o , q , strict ) === ! reverse ; } ) . slice ( offset , offset + limit ) ; } res = [ ] ; _l = Math . min ( this . length , limit + offset ) ; i = 0 ; for ( ; i < _l ; i ++ ) { if ( match ( this [ i ] , q , strict ) === ! reverse ) { if ( offset -- > 0 ) { continue ; } res . push ( this [ i ] ) ; } } return res ; }
Main function. Will be called on an ArrayDB or Array
object.
@q [Object]: the query. If it's the only one argument and it has
a 'query' property, it's used to specify other arguments,
e.g.: {
query: <the query>,
limit: <the limit>,
offset: <the offset>,
strict: <strict mode?>,
reverse: <reversed query?>
}
@limit [Number]: optional. The maximum number of results. Default
to Infinity.
@offset [Number]: optional. Default to 0.
Main function . Will be called on an ArrayDB or Array object .