当前位置:网站首页>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;
}
边栏推荐
- 递归:一维链表和数组
- [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
- DAPP for getting started with eth
- js/ts底层实现双击事件
- 如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
- Message queue addition failure
- Debug: CD cannot be used in kaggle
- 2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
- Intercept string fixed length to array
- Appium automated testing framework
猜你喜欢

nodejs基础:浅聊url和querystring模块
![[home push IMessage] software installation virtual host rental tothebuddy delay](/img/e7/eb20a773e4b674962f856d179a3769.jpg)
[home push IMessage] software installation virtual host rental tothebuddy delay

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

递归:一维链表和数组

SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍

第十届中国云计算大会·中国站:展望未来十年科技走向

2022 P cylinder filling examination content and P cylinder filling practice examination video

Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange

竞品分析撰写

js实现在可视区内,文字图片动画效果
随机推荐
China Mobile Internet of things oneos and onenet were selected in the list of 2021 Internet of things demonstration projects
【学习笔记】seckill-秒杀项目--(11)项目总结
IPv6 foundation construction experiment
[DRM] simple analysis of DRM bridge driver call process
Null and undefined
递归:一维链表和数组
Is pytorch open source?
Makefile demo
Separable bonds and convertible bonds
[brush questions] connected with rainwater (one dimension)
SAP ui5 application development tutorial 105 - detailed introduction to the linkage effect implementation of SAP ui5 master detail layout mode
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
基于Pytorch和RDKit的QSAR模型建立脚本
Recursion: quick sort, merge sort and heap sort
105. Detailed introduction of linkage effect realization of SAP ui5 master detail layout mode
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
编译文件时报错:错误: 编码GBK的不可映射字符
eth入门之DAPP
动态规划:最长回文子串和子序列
Download and install captura and configure ffmpeg in captura