-
Notifications
You must be signed in to change notification settings - Fork 0
/
reunderscore-min.js
2 lines (2 loc) · 3.62 KB
/
reunderscore-min.js
1
2
!function(){"undefined"!=typeof window&&(exports=window);var n={};n.indentity=function(n){return n},n.isArray=function(n){return Array.isArray(n)},n.isObject=function(n){return"object"==typeof n},n.each=function(r,t){if(n.isArray(r))for(var e=0;e<r.length;e++)t(r[e]);else if(n.isObject(r))for(var i in r)t(r[i])},n.map=function(r,t){var e=[];return n.each(r,function(n){e.push(t(n))}),e},n.reduce=function(r,t,e){var i=3===arguments.length;return t=t||n.indentity(),n.each(r,function(n){i?e=t(e,n):(e=n,i=!0)}),e},n.reduceRight=function(r,t,e){return n.reduce(r.reverse(),t,e)},n.find=function(r,t){if(n.isArray(r)){for(var e=0;e<r.length;e++)if(t(r[e])===!0)return r[e]}else if(n.isObject(r))for(var i in r)if(t(r[i])===!0)return r[i];return null},n.filter=function(r,t){var e=[];return n.each(r,function(n){t(n)&&e.push(n)}),e},n.where=function(n,r){for(var t,e=[],i=0;i<n.length;i++){t=!0;for(var u in r)n[i][u]!==r[u]&&(t=!1);t&&e.push(n[i])}return e},n.findWhere=function(n,r){for(var t,e=[],i=0;i<n.length;i++){t=!0;for(var u in r)n[i][u]!==r[u]&&(t=!1);if(t)return n[i]}return e},n.reject=function(r,t){var e=[];return n.each(r,function(n){t(n)||e.push(n)}),e},n.every=function(r,t){if(n.isArray(r)){for(var e=0;e<r.length;e++)if(t(r[e])===!1)return!1}else if(n.isObject(r))for(var i in r)if(t(r[i])===!1)return!1;return!0},n.some=function(r,t){if(n.isArray(r)){for(var e=0;e<r.length;e++)if(t(r[e])===!0)return!0;return!1}if(n.isObject(r))for(var i in r)if(t(r[i])===!0)return!0;return!1},n.contains=function(n,r,t){t||(t=0);for(var e=t;e<n.length;e++)if(n[e]===r)return!0;return!1},n.invoke=function(r,t){for(var e=[],i=0;i<r.length;i++){var u=r[i];n.isFunction(u[t])&&e.push(u[t].apply(u))}return e},n.pluck=function(r,t){var e=[];return n.each(r,function(n){e.push(n[t])}),e},n.max=function(r,t){var e,i;if(!n.isFunction(t))return i=r.sort(function(n,r){return parseInt(r,10)-parseInt(n,10)}),i[0];for(var u=0;u<r.length;u++){var f=t(r[u]);0===u?(e=f,i=r[u]):f>e&&(e=f,i=r[u])}return i?i:"Infinity"},n.min=function(r,t){var e,i;if(n.isFunction(t))for(var u=0;u<r.length;u++){var f=t(r[u]);0===u?(e=f,i=r[u]):f<e&&(e=f,i=r[u])}else i=r.sort(function(n,r){return parseInt(n,10)-parseInt(r,10)})[0];return i?i:"Infinity"},n.sortBy=function(r,t){return n.isFunction(t)?r.sort(function(n,r){return t(n)-t(r)}):r.sort(function(n,r){return n[t]<r[t]?-1:n[t]>r[t]?1:0})},n.groupBy=function(r,t){var e,i,u={};if(n.isFunction(t))for(i=0;i<r.length;i++)e=t(r[i]),u[e]?u[e].push(r[i]):(u[e]=[],u[e].push(r[i]));else if(n.isString(t))for(i=0;i<r.length;i++)e=r[i][t],u[e]?u[e].push(r[i]):(u[e]=[],u[e].push(r[i]));return u},n.indexBy=function(n,r){for(var t,e={},i=0;i<n.length;i++)t=n[i][r],e[t]=n[i];return e},n.countBy=function(n,r){for(var t={},e=0;e<n.length;e++){var i=r(n[e]);t[i]?t[i]++:t[i]=1}return t},n.shuffle=function(r){for(var t,e=r.length,i=Array(e),u=0;u<e;u++)t=n.getRandom(u),t!==u&&(i[u]=i[t]),i[t]=r[u];return i},n.sample=function(r,t){t=t||1;var e=n.shuffle(r);return e.splice(0,t)},n.toArray=function(n){return Array.prototype.slice.call(n)},n.size=function(r){return n.isArray(r)?r.length:n.isObject(r)?Object.keys(r).length:0},n.partition=function(r,t){var e=[],i=[],u=[];return n.each(r,function(n){t(n)?i.push(n):u.push(n)}),e.push(i),e.push(u),e},n.first=function(n,r){return r=r||1,n.slice(0,r)},n.getRandom=function(n){return Math.floor(Math.random()*n)},n.isString=function(n){return"string"==typeof n},n.isFunction=function(n){return"function"==typeof n},n.range=function(n,r,t){r||(r=n,n=0),t||(t=1);for(var e=[],i=n;i<=r;i+=t)e.push(i);return e},n.once=function(n){var r,t=!1;return function(){return t===!1&&(r=n(arguments),t=!0),r}},exports._=n}();
//# sourceMappingURL=