Last active
August 29, 2015 14:00
-
-
Save azybler/11168942 to your computer and use it in GitHub Desktop.
Refactor jquery ui datepicker code from .each to .filter & .map
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
// 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