@clarketm/supermergesort
Version:
MergeSort with superpowers! 💪
7 lines • 1.05 kB
JavaScript
/**
* Copyright (c) 2018, Travis Clarke
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.MergeSort={})}(this,function(e){"use strict";function t(e,t){return e-t}function r(e){return function(t,r){return e(t,r)<0}}function n(e){function n(e){if(e.length<=1)return e;var t=Math.trunc(e.length/2),r=e.slice(0,t),o=e.slice(t);return n(r),n(o),i(e,r,o,u)}var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;if(!(this instanceof Array||e instanceof Array))throw Error("Array type is required");var f=this instanceof Array?this:e.slice(0),u=r(o);return n(f)}function i(e,t,r,n){for(var i=0,o=0,f=0;i<t.length&&o<r.length;)n(t[i],r[o])?(e[f]=t[i],i++):(e[f]=r[o],o++),f++;for(;i<t.length;)e[f]=t[i],i++,f++;for(;o<r.length;)e[f]=r[o],o++,f++;return e}e.mergeSort=n,Object.defineProperty(e,"__esModule",{value:!0})});