View gist.js
/** | |
* 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) { |
View Flatten Array - numbers.js
const isArray = (obj) => { | |
return (typeof obj === 'object' && obj.hasOwnProperty('length')); | |
} | |
function NotAnArrayException(message) { | |
this.message = message; | |
this.name = 'NotAnArrayException'; | |
} | |
const flattenArray = list => { |
View sort-obj-by-field.js
// 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}, |