当前位置:网站首页>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;
}
边栏推荐
- [Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
- 2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
- 2022 polymerization process examination questions and polymerization process examination skills
- "Final review" 16/32-bit microprocessor (8086) basic register
- pytorch怎么下载?pytorch在哪里下载?
- eth入门之DAPP
- 第十届中国云计算大会·中国站:展望未来十年科技走向
- [mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
- sigaction的使用
- 编译文件时报错:错误: 编码GBK的不可映射字符
猜你喜欢

js实现在可视区内,文字图片动画效果

递归:一维链表和数组

在 .NET 6 项目中使用 Startup.cs

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

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

Message queue addition failure

Cnopendata China Customs Statistics

What is pytorch? Is pytorch a software?

在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码

TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
随机推荐
300+篇文献!一文详解基于Transformer的多模态学习最新进展
【学习笔记】seckill-秒杀项目--(11)项目总结
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
Ffmpeg recording screen and screenshot
Recursion: depth first search
Interaction free shell programming
Mutex and rwmutex in golang
在 .NET 6 项目中使用 Startup.cs
Shardingsphere dynamic data source
[national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
pytorch怎么下载?pytorch在哪里下载?
以两列的瀑布流为例,我们应该怎么构建每一列的数组
用户体验五要素
For instruction, uploading pictures and display effect optimization of simple wechat applet development
Makefile demo
C语言HashTable/HashSet库汇总
js中#号的作用
Half of 2022 is over, so we must hurry up
JS native common knowledge