Skip to content

Instantly share code, notes, and snippets.

View WeeHorse's full-sized avatar

Benjamin Berglund WeeHorse

View GitHub Profile
@WeeHorse
WeeHorse / array-sorting-and-sub-sorting.js
Created July 11, 2018 09:07 — forked from dfkaye/array-sorting-and-sub-sorting.js
secondary or sub sorting an array in JavaScript
// 29 Sep 2017
// 4 Oct 2017 - add name object example.
// 14 Nov 2017 - pass `a.name, b.name` to `byName()`; rename `test` as `diff`.
// 1 Jan 2018 - made some functions more readable.
// Inspired by post at https://alistapart.com/article/what-i-talk-about-when-i-talk-about-sorting
// which covers an example of sorting by age, but does not ensure items of same age are secondarily
// sorted by name in alphabetical order.
// This snippet shows how to do that whether names are strings or objects with first and last properties.