How do I change the places reservation in mobile

0

I used jQuery-Seat-Charts to make a layout and place reservation, the problem is that when it's in mobile I wanted it another way.

On the desktop it looks like this:

 map: [
          'a[,4]a[,8]a[,12]a[,16]a[,20]a[,24]a[,28]a[,32]a[,36]a[,40]a[,44]a[,48]a[,53]',
          'a[,3]a[,7]a[,11]a[,15]a[,19]a[,23]a[,27]a[,31]a[,35]a[,39]a[,43]a[,47]a[,52]',
          '____________a[,51]',
          'a[,2]a[,6]a[,10]a[,14]a[,18]a[,22]a[,26]a[,30]a[,34]a[,38]a[,42]a[,46]a[,50]',
          'a[,1]a[,5]a[,9]a[,13]a[,17]a[,21]a[,25]a[,29]a[,33]a[,37]a[,41]a[,45]a[,49]',
        ],

And in mobile, I want to:

 map:[
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aaaaa',
        ],

At this moment it is so for mobile and desktop: AndIwantittolooklikethisonmobile:

    
asked by anonymous 15.03.2018 / 11:22

1 answer

1

What you are trying to do is basically transpose a 2D array. The problem is that in your case it is not even a 2D array but rather an array of strings which adds difficulty to the problem.

In addition to the example output you have does not play with the input, because the input has the numbers of places with a[,1] , a[,2] and in the output you no longer have this discrimination getting only aa .

I put here a simplified solution that suits what you have, but which you may have to adjust using the information you use. Still, it should give you an idea of how to approach the problem. The output will be the same with the places as it has in the input.

const lugares = [
      'a[,4]a[,8]a[,12]a[,16]a[,20]a[,24]a[,28]a[,32]a[,36]a[,40]a[,44]a[,48]a[,53]',
      'a[,3]a[,7]a[,11]a[,15]a[,19]a[,23]a[,27]a[,31]a[,35]a[,39]a[,43]a[,47]a[,52]',
      '____________a[,51]',
      'a[,2]a[,6]a[,10]a[,14]a[,18]a[,22]a[,26]a[,30]a[,34]a[,38]a[,42]a[,46]a[,50]',
      'a[,1]a[,5]a[,9]a[,13]a[,17]a[,21]a[,25]a[,29]a[,33]a[,37]a[,41]a[,45]a[,49]',
    ];

const divisores = {'a':true , '_':true};

//colocar espaços antes de 'a' e '_' para de seguida transformar em 2D
let lug2d = lugares.map(fila => fila.split('').
  map((letra, pos) => (pos != 0 && letra in divisores) ? ' '+letra : letra).join(''));

//transformar em 2d à custa de split pelos espaços colocados previamente
lug2d = lug2d.map(fila => fila.split(' '));

//criar o array 2d final para a transposição
let lug2dTransposto = [];
for (let i = 0; i < lug2d[0].length; ++i){
  lug2dTransposto.push([]);
}

//transpor
for(let i = lug2d.length - 1; i >=0 ; --i){
    for(let j = 0; j < lug2d[i].length ; ++j){
        lug2dTransposto[j].push(lug2d[i][j]);
    }
}

//retransformar do array 2d para array de strings
let lugFinal = lug2dTransposto.map(fila => fila.join(''));
console.log(lugFinal);
    
15.03.2018 / 12:43