Skip to content

Instantly share code, notes, and snippets.

@azybler
Last active August 29, 2015 14:00
Show Gist options
  • Save azybler/11168942 to your computer and use it in GitHub Desktop.
Save azybler/11168942 to your computer and use it in GitHub Desktop.
Refactor jquery ui datepicker code from .each to .filter & .map
// before
var schedulesTmp = $('form#interview-schedule input[name^="schedule-datetime"]');
var schedules1 = [];
schedulesTmp.each(function() {
if (null !== $(this).datepicker('getDate')) {
schedules1.push($(this).val());
}
});
alert(schedules1.length + ' ' + schedules1[0] + ' ');
// after
var schedules2 = $('form#interview-schedule input[name^="schedule-datetime"]').filter(function() {
return null !== $(this).datepicker('getDate');
}).map(function(i, n) {
return $(n).val();
}).get();
alert(schedules2.length + ' ' + schedules2[0] + ' ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment