I'm trying to group some JSON data into pairs, for a slider, but we've got a layout rule as below
Portrait | Portrait
Landscape
Portrait | Portrait
Portrait | Portrait
Landscape
Landscape
So in the gallery, 2 portrait images can be next to each other, however landscape images use a view of their own.
The data I've got follows this basic setup
var photos = [
{
"id": "1",
"landscape": false
},
{
"id": "2",
"landscape": false
},
{
"id": "3",
"landscape": true
},
{
"id": "4",
"landscape": true
},
{
"id": "5",
"landscape": false
},
{
"id": "6",
"landscape": true
},
{
"id": "7",
"landscape": false
},
{
"id": "8",
"landscape": false
},
{
"id": "9",
"landscape": false
},
{
"id": "10",
"landscape": false
},
{
"id": "11",
"landscape": false
},
{
"id": "12",
"landscape": true
},
{
"id": "13",
"landscape": true
},
{
"id": "14",
"landscape": false
},
{
"id": "15",
"landscape": true
}
];
However I need to format it in a similar structure to below - trying to keep the original order of the data as intact as possible.
var views = [
[{id:"1", landscape: false},{id:"2", landscape: false}],
[{id:"3", landscape: false},{id:"4", landscape: false}],
[{id:"5", landscape: true}],
[{id:"6", landscape: false},{id:"7", landscape: false}],
[{id:"7", landscape: true}]
]; //etc etc
We don't have access to jQuery, but have the full _underscore.js library to hand and of course native javascript.
Could somebody please shed some light on how this would be possible?
Many thanks