Skip to content

Instantly share code, notes, and snippets.

@ericcornelissen
ericcornelissen / array-string-sort.js
Last active January 28, 2019 20:03
JavaScript Array prototype method to sort strings containing numbers correctly
/**
* Sort an array of string alpha-numerically.
*
* @example
* // returns ['1', '2', '10', '20'] rather then ['1', '10', '2', '20']
* ['1', '20', '10', '2'].strSort();
*
* @return {array} The alpha-numerically sorted array.
* @license The-Unlicense
*/
@ericcornelissen
ericcornelissen / function-pipeline-creator.js
Last active May 15, 2019 23:33
Functional JavaScript: simple function pipeline creators
let pipe = function() {
let functions = arguments,
intermediate = undefined;
return function() {
intermediate = functions[0].apply(this, arguments);
for(let i = 1; i < functions.length; i++) {
intermediate = functions[i](intermediate);
}