当前位置:网站首页>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;
}
边栏推荐
- Null and undefined
- Ffmpeg download and installation tutorial and introduction
- [Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
- pytorch难学吗?如何学好pytorch?
- 国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来
- 『期末复习』16/32位微处理器(8086)基本寄存器
- Web会话管理安全问题
- Write it down once Net travel management background CPU Explosion Analysis
- [national programming] [software programming - Lecture Video] [zero foundation introduction to practical application]
- 树莓派如何连接WiFi
猜你喜欢

"Final review" 16/32-bit microprocessor (8086) basic register

Application of I2C protocol of STM32F103 (read and write EEPROM)

105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
![[embedded module] OLED display module](/img/c4/474f5ee580d132654fbd1a4cd53bab.jpg)
[embedded module] OLED display module

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

『期末复习』16/32位微处理器(8086)基本寄存器

In Net 6 project using startup cs

Appium自动化测试框架

中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
![[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification](/img/30/c840e28c0ef7c8ce574dcde4363863.jpg)
[Apple Push] IMessage group sending condition document (push certificate) development tool pushnotification
随机推荐
pytorch项目怎么跑?
JMeter starts from zero (III) -- simple use of regular expressions
2022 polymerization process examination questions and polymerization process examination skills
2022-07-02:以下go语言代码输出什么?A:编译错误;B:Panic;C:NaN。 package main import “fmt“ func main() { var a =
Write it down once Net travel management background CPU Explosion Analysis
基于Pytorch和RDKit的QSAR模型建立脚本
用户体验五要素
[brush questions] connected with rainwater (one dimension)
Makefile demo
CEPH Shangwen network xUP Nange that releases the power of data
Practical operation of vim
『期末复习』16/32位微处理器(8086)基本寄存器
ZIP文件的导出
2022 tea master (primary) examination questions and tea master (primary) examination question bank
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
js实现在可视区内,文字图片动画效果
IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
Ffmpeg recording screen and screenshot
8.8.2-PointersOnC-20220214
Recursion: one dimensional linked lists and arrays