Ok, it took me most of the day to come up with the following fiddle https://jsfiddle.net/Mardonis/3y8mp940/4/ to have a start on the process of finding a way to convert a basic layout to the more intricate array you provided. It shows a console.log version of the original and a html version to show the converted way once its figured out. For now it just shows the same.