Last active
September 5, 2015 18:11
-
-
Save Ahrengot/c93ee0992b3e78524a11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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