当前位置:网站首页>2020-07 study notes sorting
2020-07 study notes sorting
2022-06-11 11:41:00 【Michael18811380328】
For-in and for-of
Official documents :https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/for…of
Conventional for Cycles have limitations ,forEach and map Adapt to array loops , So there is for in and for of loop .
for…of… loop : You can loop through enumerable objects ( Array , object ,Map, set, Pseudo array , Constructors, etc ), Loop to get internal elements , have access to break Jump out of , Properties and methods on the prototype chain of enumerable objects cannot be cycled .
for…in… You can loop through the items of an array , And functions on objects, etc ( Including functions on the prototype chain ), Attention should be paid to before use .
Conclusion : Traversing arrays takes precedence for forEach map Handle , Traversing objects takes precedence for…of… Get the properties of an object
in-place algorithm
Do not use additional heap memory space ( You can use temporary variables ) Use : Invert array ; Palindrome
Bisection algorithm
Two points , Judge , Then recursively or while loop ;
The binary premise is the sorted array ; Determine the boundary and final value of the dichotomy , Avoid the dead cycle ;
Bisection algorithm can be used to quickly find whether there are specified elements in the array ; Or quick sort ( Select the first element in the array as the root element , Then define two empty arrays , Store elements larger and smaller than the root element respectively , Then traverse the remaining items of the array and compare them with the root element , When Tao is in two empty arrays , Then put the large array , Root element , Small arrays can be combined ) Large and small arrays continue to perform binary sorting .
Greedy Algorithm
It is mainly used in situations where problems can be decomposed step by step , Greedy algorithms may not be the best way , Therefore, we need to consider whether it is suitable to use greedy algorithm . The main problem that can be solved is the knapsack problem ( Limited weight , Try to pack the most valuable goods ) Then the price weight ratio of different products can be calculated , Then store different items . Or coin change, etc .
Number formatting
Intl.NumberFormat(locale, option).format(10000);
This built-in method , You can convert a number into different currency formats , Separator , Company , Significant figures, etc .
The first parameter is locale Language , For example, it was introduced into Germany , So the decimal point and comma are the opposite settings .
The second parameter is option Optional parameters , Configuration object . The properties of an object are style currency unit You can set currency number separator, etc .
performance optimization
React in , The goal of performance optimization is to reduce unnecessary rendering
Built-in methods : Use shouldComponentUpdate Judge state props When the change , Update component ; Use PureComponent Set pure components , If it's a pure component , Then the components are automatically shallow compared props Then render , This PureComponent Will be inherited into sub components , So you need to use this component in the leaf node . If it is a function component, use React.memo() Optimize ( Not actually used ).
Manual optimization : Reduce unnecessary from parent components to child components Props; Reduce State Use , Try to use attributes , Avoid unnecessary rendering ; If it's a reference type , You need to clone Copy new objects , Implement component update .
Ref yes Null Of bug
In some cases ,this.ref.current yes null, Can't get... Directly DOM node . Usually the cause of the problem is , During interface initialization , This node has not been rendered yet , therefore DOM Can't get , What you get is NUll. It is usually OK to call in the event callback function , But in render perhaps DidMount It may not be obtained in the stage .
setState Passing objects and functions
setState Execution is asynchronous , If you pass the object , Errors may occur .
If this function is called frequently , Then when the latter is executed , Acquired this.state.count It's wrong. , The result is wrong
this.setState({
count: this.state.count + 1,
});
You can pass a function instead , Get the latest every time state, So the count is correct
this.setState((state) => {
return {
count: state + 1
}
});
bash Create operation files in batch
Need to call bash Of API( Create delete directory , Create delete file , loop , Add the way to write variables in the operation )
#!/bin/bash
for a in {
1..10}
do
mkdir test$a
done
Use for-do-done Complete the cycle (for The condition of the loop is outside , Note that there are two points ) Deleting a file cannot be rolled back , Note the script execution
边栏推荐
- [file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)
- Maximum water container
- 设置默认收货地址【项目 商城】
- WordPress user name modification plug-in: username changer
- my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题
- 命令模式--进攻,秘密武器
- Where is it safer to open an account for soda ash futures? How much capital is needed to trade soda ash futures at present?
- 202年最新热门收益较高的年金险产品是什么?
- Typeerror: argument of type "Int 'is not Iterable
- Etcd介绍
猜你喜欢

Uncaught TypeError: Cannot set property ‘next‘ of undefined 报错解决

木瓜移动CFO刘凡 释放数字时代女性创新力量

web开发选型,web开发毕业谁
![[第二章 基因和染色体的关系]生物知识概括–高一生物](/img/f0/9f78682798a7874ba176797a6b22ca.png)
[第二章 基因和染色体的关系]生物知识概括–高一生物

Intermediate web development engineer, interview questions + Notes + project practice
![[file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)](/img/30/79516390c2b2b50a224eaa84a0c1c9.jpg)
[file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)

設置默認收貨地址【項目 商城】

Typeerror: argument of type "Int 'is not Iterable
![my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题](/img/bd/a28e74654c7821b3a9cd9260d2e399.png)
my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题

Lifeifei: I am more like a scientist in physics than an engineer
随机推荐
灵动边栏(Widget)插件:MO Widgets
MSF CS OpenSSL traffic encryption
Method of converting VOC format data set to Yolo format data set
Let WordPress support registered users to upload custom avatars
Is it safe for Xiaobai to open an account directly on the flush?
The tutor transferred me 800 yuan and asked me to simulate a circuit (power supply design)
What is the latest popular annuity insurance product with higher income in 202?
WordPress登录页面美化插件:Login Designer推荐
js合并两个对象(面试题)
Introduction to database system - Chapter 2 - relational database (2.1~2.3) (important knowledge points)
普通人应当如何挑选年金险产品?
UCI-HAR数据集的处理
17.4创建多个线程、数据共享问题分析与案例代码
如何养成一个好习惯?靠毅力?靠决心?都不是!
NFT digital collection app system construction
全国多年太阳辐射空间分布数据1981-2022年、气温分布数据、蒸散量数据、蒸发量数据、降雨量分布数据、日照数据、风速数据
NFT digital collection system platform construction
苹果MobileOne: 移动端仅需1ms的高性能骨干
Use yolov3 to train yourself to make datasets and get started quickly
Collection of practical WordPress plug-ins (under update)