The author is misrepresenting imperative code [0].
Instead of the 42 lines of code he thinks is imperative, but really is already functional-compatible, this is what I would write:
var getIncompleteTaskSummariesForMember_imperative = function(memberName) {
return fetchData().then(function(data) {
var tasks = data.tasks;
var results = [];
for (var i = 0; i < tasks.length; i++) {
var task = tasks[i];
if (task.member == memberName && !task.complete) {
results.push({
id: task.id,
dueDate: task.dueDate,
title: task.title,
priority: task.priority
})
}
}
results.sort(function(first, second) {
return first.dueDate - second.dueDate;
});
return results;
});
}
Still longer than the 10 lines of functional code, but a much more fair comparison.[0]: http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk...