I'm looking for some JavaScript code improvement and optimization. Is it possible to optimize this block of code (for example, remove double array loop)?
replace: function(ex, str) {
var arr = str.match(/{add_([A-Z]+)}/gi);
if (arr && arr.length) {
arr.each(function(e){
var id = e.replace('{add_','').replace('}',''),
o = Core.get_data_by_id(ex.extensions, id);
if (o && o.status =="1") {
str = str.replace('{add_'+id+'}', o.html);
}
});
}
var arr2 = str.match(/{banner_([0-9]+)}/gi);
if (arr2 && arr2.length) {
arr2.each(function(e){
var id = e.replace('{banner_','').replace('}',''),
b = Core.get_data_by_id(ex.banners, id);
if (b && b.status =="1" && b.code && b.code.length) {
var content = '<div class="units-row banner_'+b.id+'"><ul>' +
b.code.each(function(s){
content += '<li>'+s.code+'</li>';
});
content += '</ul></div>';
str = str.replace('{banner_'+id+'}', content);
}
});
}
return str;
}