Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Meneses danielmeneses

  • Braga, Portugal
View GitHub Profile
@danielmeneses
danielmeneses / gist.js
Last active Nov 20, 2018
sort array - mean calc
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 => {
@danielmeneses
danielmeneses / sort-obj-by-field.js
Created Jan 30, 2017
Sort Objects by field - JS
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},
You can’t perform that action at this time.