As For JavaScript...
Обсуждения — @AsForJsTalks
Post #1050
1.88K
Чтобы Вы в этом коде, назвали бы отвратительным и как бы Вы его (код или часть его) переписали
const dashboardConfig = [{
id: 'filters',
gridAttributes: {
width: 6,
height: 1,
yPos: 0,
xPos: 3,
},
}, {
id: 'info',
gridAttributes: {
width: 3,
height: 2,
yPos: 1,
xPos: 1,
},
}, {
id: 'more',
gridAttributes: {
width: 4,
height: 1,
yPos: 2,
xPos: 7,
},
}, ];
const columns = 12
const rows = Math.max(...dashboardConfig.map( ({gridAttributes}) => gridAttributes.yPos + gridAttributes.height), );
console.log(rows)
const grid = Array.from({
length: rows
}, () => Array.from({
length: columns
}).fill('.'))
dashboardConfig.forEach( (entry) => {
const {id, gridAttributes} = entry
const {xPos, yPos, width, height} = gridAttributes
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
grid[yPos + j][xPos + i] = id
}
}
}
)
const result = grid.map( (row) => `"${row.join(' ')}"`).join('\n')
console.log( result );- ❤ 2
- 👨💻 2

