Last active
August 29, 2015 14:22
-
-
Save nltesown/07631fa0f4af05fbdf77 to your computer and use it in GitHub Desktop.
Takes a jQuery object of checkbox elements and returns info about the checked ones
This file contains 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
// Takes a jQuery object of checkbox elements and returns: | |
// - An array of the IDs of the checked ones | |
// - (if asCollection is true) A collection of the checked ones where key=ID, value=true | |
// Dependency: jQuery, underscore/lodash | |
function readCheckboxes($cb, asCollection) { | |
return _($cb.filter(":checked")) | |
.map(function(item) { | |
return item.id; | |
}) | |
.thru(function(item) { | |
return (!!asCollection ? _(item).zipObject().mapValues(function() { | |
return true; | |
}).value() : item); | |
}) | |
.value(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
btw I really love the functional style where the body of a function is only a return statement.