> Another thought is that you could just do a replace on 0, 1 and 2 in the
> string: replace each number with the div you want, then wrap that in a div.

Yeah, I was wondering whether the regexp engine would be faster.
Something like this:

for(var item in items){
  html.push(
    '<div class="wrapper">',
    process(items[item]),
    '</div>'
  );


function process(item)
{
  return item.replace(/\d/g, function(d){
    return '<div class="'+
      ["gray","blue","red][d]+
      '">&nbsp;</div>';
  });
}

Reply via email to