map = {}; for (y = 2; y <= Bottom; y++) { key = [3,y]; if (key != "") { map[key] = {}; for (x = 4; x <= Right; x++) { map[key][x] = [x,y]; } } } for (y = 2; y <= Bottom; y++) { key = [1,y]; if (key in map) { [3,y] = key; for (x = 4; x <= Right; x++) { [x,y] = map[key][x]; } } else { [3,y] = ""; for (x = 4; x <= Right; x++) { [x,y] = ""; } } }