Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including grin with all npm packages installed. Try it out:

var grin = require("grin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

grin v1.0.4

Super simple and non-recursive merge sort

grin

Build Status

Simple non-recursive implementation of merge sort. Originally based on this Java implementation, by @nolanlawson now mostly written by @calvinmetcalf.

Status, should work, does modify the array in place, will not work on sparse arrays exactly like native but that's ok.

Usage

$ npm install grin

Then in code:

var sort = require('grin');
var arr = [3, 2, 1, 4, 10];

// [1, 10, 2, 3, 4]
var sortedNaturally = sort(arr);

// [1, 2, 3, 4, 10]
var sortedNumerically = sort(arr, function (a, b) { return a - b; });

Testing

Unit tests:

$ npm test

Coverage tests:

$ npm run coverage

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free