Skip to content

Instantly share code, notes, and snippets.

@Ahrengot
Last active September 5, 2015 18:11
Show Gist options
  • Select an option

  • Save Ahrengot/c93ee0992b3e78524a11 to your computer and use it in GitHub Desktop.

Select an option

Save Ahrengot/c93ee0992b3e78524a11 to your computer and use it in GitHub Desktop.
import _ from 'underscore';
let toNumbers = function(arr) {
return _.map(arr, _.partial(parseInt, _, 10));
}
let execFuncs = function(arr) {
return _.map(arr, function(item) {
return _.isFunction(item) ? item() : item;
})
}
var arr = [
false,
16,
1,
"jens",
function() {
return 2 * 5;
},
17,
16,
["2", 3, "four", 5, 6, [90, [[100]]]]
];
var funkyTown = _.compose(
_.sortBy, // Sort
_.compact, // remove false values
toNumbers, // Convert strings to numbers
execFuncs, // Get result of nested functions
_.flatten // un-nest arrays
);
console.log( funkyTown( arr ) );
// Result =>
// [1, 2, 3, 5, 6, 10, 16, 16, 17, 90, 100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment