Skip to content

Instantly share code, notes, and snippets.

@mailtruck
Created November 6, 2016 04:14
Show Gist options
  • Save mailtruck/43553080f339574f21ec0594f9850b2f to your computer and use it in GitHub Desktop.
Save mailtruck/43553080f339574f21ec0594f9850b2f to your computer and use it in GitHub Desktop.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
Array.from||(Array.from=function(){var n=Object.prototype.toString,e=function(e){return"function"==typeof e||"[object Function]"===n.call(e)},t=function(n){var e=+n;return isNaN(e)?0:0!==e&&isFinite(e)?(e>0?1:-1)*Math.floor(Math.abs(e)):e},o=Math.pow(2,53)-1,r=function(n){var e=t(n);return Math.min(Math.max(e,0),o)};return function(n){var t=this,o=Object(n);if(null==n)throw new TypeError("Array.from requires an array-like object - not null or undefined");var i,a=arguments.length>1?arguments[1]:void 0;if(void 0!==a){if(!e(a))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(i=arguments[2])}for(var u,c=r(o.length),l=e(t)?Object(new t(c)):Array(c),f=0;c>f;)u=o[f],l[f]=a?void 0===i?a(u,f):a.call(i,u,f):u,f+=1;return l.length=c,l}}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment