@clarketm/superinsertionsort
Version:
InsertionSort with superpowers! 💪
7 lines • 904 B
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(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.InsertionSort={})}(this,function(n){"use strict";function r(n,r){return n-r}function e(n){return function(r,e){return n(r,e)<0}}function t(n,r,e){if(r!==e){var t=[n[e],n[r]];n[r]=t[0],n[e]=t[1]}}function i(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;if(!(this instanceof Array||n instanceof Array))throw Error("Array type is required");var o=this instanceof Array?this:n.slice(0),f=e(i);return function(n){for(var r=0;r<n.length-1;r++)for(var e=r;e>=0&&f(n[e+1],n[e]);e--)t(n,e,e+1);return n}(o)}n.insertionSort=i,Object.defineProperty(n,"__esModule",{value:!0})});