当前位置:网站首页>Taking two column waterfall flow as an example, how should we build an array of each column
Taking two column waterfall flow as an example, how should we build an array of each column
2022-07-03 04:00:00 【Attacking-Coder】
Ideas
Add new image elements to the column with the lowest height , Until it is longer than the other column . Then add elements to the short column
Code ( Example )
// data Is an array containing all picture information of the waterfall stream
// numberOfColumns It represents the number of waterfall flow columns , Our case is 2 Column
function classifyData(data: any[], numberOfColumns: number): any[] {
const result: any[] = [];
// Array initialization
for (let i = 0; i < numberOfColumns; i++) {
result.push({
height: 0,
contents: []
});
}
data.forEach((item) => {
const minHeight = Math.min(...result.map((list) => list.height));
const minList = result.find((list) => list.height === minHeight);
// The principle of this function is to add an array after the column that is short
minList.contents.push(item);
minList.height += item.width === 0 ? 0 : item.height / item.width;
});
return result;
}
边栏推荐
- Practical operation of vim
- leetcode:297. 二叉树的序列化与反序列化
- Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences
- ZIP文件的导出
- 【学习笔记】seckill-秒杀项目--(11)项目总结
- vim 的实用操作
- Reflection and planning of a sophomore majoring in electronic information engineering
- 中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
- Cnopendata China Customs Statistics
- Dynamic programming: longest common substring and longest common subsequence
猜你喜欢

CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes

IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network

2022 polymerization process examination questions and polymerization process examination skills

How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo

Interaction free shell programming

CEPH Shangwen network xUP Nange that releases the power of data

因果AI,下一代可信AI的产业升级新范式?

递归:一维链表和数组

leetcode:297. 二叉树的序列化与反序列化

js中#号的作用
随机推荐
有监督预训练!文本生成又一探索!
【刷题篇】多数元素(超级水王问题)
Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
记一次 .NET 差旅管理后台 CPU 爆高分析
8.8.2-PointersOnC-20220214
C language hashtable/hashset library summary
2022 mobile crane driver examination registration and mobile crane driver operation examination question bank
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
eth入门之DAPP
Wechat applet + Alibaba IOT platform + Hezhou air724ug built with server version system analysis
[mathematical logic] predicate logic (first-order predicate logic formula | example)
QSAR model establishment script based on pytoch and rdkit
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
Arduino application development - LCD display GIF dynamic diagram
释放数据力量的Ceph-尚文网络xUP楠哥
js/ts底层实现双击事件
Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
DAPP for getting started with eth