当前位置:网站首页>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;
}
边栏推荐
- 【DRM】DRM bridge驱动调用流程简单分析
- Idea shortcut keys
- 在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
- Is pytorch open source?
- 2022 tea master (primary) examination questions and tea master (primary) examination question bank
- 8.8.2-PointersOnC-20220214
- Hutool dynamically adds scheduled tasks
- IPv6 foundation construction experiment
- 用户体验五要素
- 第十届中国云计算大会·中国站:展望未来十年科技走向
猜你喜欢

How does the pytorch project run?

Is it better to speculate in the short term or the medium and long term? Comparative analysis of differences

When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker

Web session management security issues

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

没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
![[brush questions] connected with rainwater (one dimension)](/img/21/318fcb444b17be887562f4a9c1fac2.png)
[brush questions] connected with rainwater (one dimension)

nodejs基础:浅聊url和querystring模块

Ffmpeg download and installation tutorial and introduction

毕设-基于SSM宠物领养中心
随机推荐
[mathematical logic] propositional logic (propositional and connective review | propositional formula | connective priority | truth table satisfiable contradiction tautology)
pytorch开源吗?
Web会话管理安全问题
SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
深潜Kotlin协程(十九):Flow 概述
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
Role of JS No
Analysis of the reason why the server cannot connect remotely
DAPP for getting started with eth
Deep dive kotlin synergy (19): flow overview
【毕业季·进击的技术er】职场人的自白
Half of 2022 is over, so we must hurry up
第十届中国云计算大会·中国站:展望未来十年科技走向
Simple wechat applet development page Jump, data binding, obtaining user information, obtaining user location information
What is the correct way to compare ntext columns with constant values- What's the right way to compare an NTEXT column with a constant value?
Deep dive kotlin synergy (20): build flow
树莓派如何连接WiFi
[mathematical logic] propositional logic (judgment of the correctness of propositional logic reasoning | formal structure is eternal truth - equivalent calculus | deduction from premise - logical reas
Makefile demo
Social phobia of contemporary young people (III)