lib/libs.js
function first (o, n) {
                    var gotN = (n === 0 ? true : !!n),
                        v;

                    n = parseInt(n, 10);
                    n = isNaN(n) || !isFinite(n) ? 1 : n;

                    if(typeof o === 'boolean') {
                        return o;
                    }
                    else if(typeof o !== 'object') {
                        if(n !== 0) v = o.toString().slice(0, n); else return undefined;
                    }
                    else if(o instanceof Array) {
                        if(n === 1 && !gotN) return o[0];
                        if(n === 0 && !gotN) return undefined;

                        return n !== 0 ? o.slice(0, n) :  [];
                    }
                    else {
                        v = {};
                        libs.object.each(o, 0, n - 1, function (item, key) { v[key] = item; });
                        var keys = getKeys(v);
                        if(n === 1 && !gotN && keys.length === 0) return undefined;

                        return keys.length === 1 && !gotN ? v[keys[0]] : v;
                    }
                    return v.length === 1 && !gotN ? v[0] : v;
                }
function first (o, n) {
                    var gotN = (n === 0 ? true : !!n),
                        v;

                    n = parseInt(n, 10);
                    n = isNaN(n) || !isFinite(n) ? 1 : n;

                    if(typeof o === 'boolean') {
                        return o;
                    }
                    else if(typeof o !== 'object') {
                        if(n !== 0) v = o.toString().slice(0, n); else return undefined;
                    }
                    else if(o instanceof Array) {
                        if(n === 1 && !gotN) return o[0];
                        if(n === 0 && !gotN) return undefined;

                        return n !== 0 ? o.slice(0, n) :  [];
                    }
                    else {
                        v = {};
                        libs.object.each(o, 0, n - 1, function (item, key) { v[key] = item; });
                        var keys = getKeys(v);
                        if(n === 1 && !gotN && keys.length === 0) return undefined;

                        return keys.length === 1 && !gotN ? v[keys[0]] : v;
                    }
                    return v.length === 1 && !gotN ? v[0] : v;
                }
Returns the first n elements of an object. If the object is an array, and only one items is retrieved,
that item will be returned, rather than an array.
@param {Object} o The object to operate on.
@param {Number=} [n=1] The number of elements to return
@return {Array<*>} The first n elements of the array.