当前位置:网站首页>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;
}
边栏推荐
- 动态规划:最长公共子串和最长公共子序列
- Read a paper_ ChineseBert
- 树莓派如何连接WiFi
- [daily question] dichotomy - find a single dog (Bushi)
- TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
- 300+篇文献!一文详解基于Transformer的多模态学习最新进展
- 【学习笔记】seckill-秒杀项目--(11)项目总结
- IPv6 foundation construction experiment
- [Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
- Deep dive kotlin synergy (19): flow overview
猜你喜欢
For instruction, uploading pictures and display effect optimization of simple wechat applet development
学会pytorch能干什么?
The latest analysis of the main principals of hazardous chemical business units in 2022 and the simulated examination questions of the main principals of hazardous chemical business units
JS native common knowledge
Error in compiled file: error: unmapped character encoding GBK
释放数据力量的Ceph-尚文网络xUP楠哥
MPLS setup experiment
Appium automated testing framework
What is pytorch? Is pytorch a software?
2022 tea master (primary) examination questions and tea master (primary) examination question bank
随机推荐
【全民编程】《软件编程-讲课视频》【零基础入门到实战应用】
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
在 .NET 6 项目中使用 Startup.cs
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
8.8.2-PointersOnC-20220214
Recursive use and multi-dimensional array object to one-dimensional array object
[national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
eth入门之DAPP
C语言HashTable/HashSet库汇总
In Net 6 project using startup cs
Deep dive kotlin synergy (19): flow overview
Download and install captura and configure ffmpeg in captura
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
第十届中国云计算大会·中国站:展望未来十年科技走向
The 10th China Cloud Computing Conference · China Station: looking forward to the trend of science and technology in the next decade
Analysis of the reason why the server cannot connect remotely
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr
Bisher - based on SSM pet adoption center
[DRM] simple analysis of DRM bridge driver call process