complete function 'build-grid(array)'