Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When creating a 2d grid array with all values the same, slicing one row multiple times works way faster than creating each row for each column.

   for(var y=h;y>=0; y--) row.push(0);
   for(var x=w; x>=0; x--) grid[x] = row.slice(0);
It seems to me that this method should work without any problems, but I may be wrong..


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: