This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Merge sort - high performance sorting | |
*/ | |
const mergeSort = (input, field) => { | |
const splitted = []; | |
for (let i = 0; i < input.length; i++) splitted.push([input[i]]); | |
const merged = (function merge(arr) { | |
const tempResult = []; | |
for (let i = 0; i < arr.length; i += 2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isArray = (obj) => { | |
return (typeof obj === 'object' && obj.hasOwnProperty('length')); | |
} | |
function NotAnArrayException(message) { | |
this.message = message; | |
this.name = 'NotAnArrayException'; | |
} | |
const flattenArray = list => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// My own implementation of merge sort (by object field) | |
var a = [ | |
{name: "Mr. Burns", age: 145}, | |
{name: "Moe", age: 37}, | |
{name: "Apu", age: 39}, | |
{name: "Carl", age: 34}, | |
{name: "Homer Simpson", age: 38}, | |
{name: "Marge Simpson", age: 36}, | |
{name: "Lisa Simpson", age: 12}, | |
{name: "Bart Simpson", age: 34}, |