JavaScript: Can this code be refactored to a more functional programming style? -
can code chained , loop abstracted away? using map , filter?
function listviewfilter(){ // test var datefiltered = containerdata.filter(function (obj){ // remove dates of 010 return !/010/.test(obj.eventdate); }); var namefiltered = []; (var = 0; < datefiltered.length; i++){ // remove eventnames.name if empty string if (datefiltered[i].eventnames[0].name == "") continue; else namefiltered.push(datefiltered[i]); } filtered = namefiltered; }
sure, for
loop nothing filter:
function listviewfilter() { var datefiltered = containerdata.filter(function(obj) { // remove dates of 010 return !/010/.test(obj.eventdate); }); var namefiltered = datefiltered.filter(function(obj, i) { // remove eventnames.name if empty string return obj.eventnames[0].name != ""; }); filtered = namefiltered; }
or in short
function listviewfilter() { filtered = containerdata.filter(function(obj) { return !/010/.test(obj.eventdate) && obj.eventnames[0].name != ""; }); }
Comments
Post a Comment